nisi u pravu jer:
Kôd:
mysql> explain SELECT m.*, c.description FROM master m
-> LEFT JOIN categories c ON m.category_id = c.category_id;
+----+-------------+-------+--------+---------------+---------+---------+-----------------------+-------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+--------+---------------+---------+---------+-----------------------+-------+-------+
| 1 | SIMPLE | m | ALL | NULL | NULL | NULL | NULL | 40427 | |
| 1 | SIMPLE | c | eq_ref | PRIMARY | PRIMARY | 4 | measure.m.category_id | 1 | |
+----+-------------+-------+--------+---------------+---------+---------+-----------------------+-------+-------+
2 rows in set (0.00 sec)
mysql> alter table master add index category_id(category_id);
Query OK, 40000 rows affected (1.06 sec)
Records: 40000 Duplicates: 0 Warnings: 0
mysql> explain SELECT m.*, c.description FROM master m
-> LEFT JOIN categories c ON m.category_id = c.category_id;
+----+-------------+-------+--------+---------------+-------------+---------+-----------------------+-------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+--------+---------------+-------------+---------+-----------------------+-------+-------------+
| 1 | SIMPLE | m | index | NULL | category_id | 5 | NULL | 40715 | Using index |
| 1 | SIMPLE | c | eq_ref | PRIMARY | PRIMARY | 4 | measure.m.category_id | 1 | |
+----+-------------+-------+--------+---------------+-------------+---------+-----------------------+-------+-------------+
2 rows in set (0.00 sec)
Dakle, nakon dodavanja index on se
koristi (type kolona u explain outputu).