-- tested with MySQL 5.6 -- Type ALL - no index used. EXPLAIN SELECT h.date, h.price, h.name FROM history h JOIN history h1 ON h.id = h1.id; -- at least, it uses index now and no sort in Extra EXPLAIN SELECT h.date, h.price, h.name FROM history h JOIN history h1 ON h.id = h1.id ORDER BY h.id;
id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
---|---|---|---|---|---|---|---|---|---|---|---|
1 | SIMPLE | h | null | ALL | PRIMARY | null | null | null | 1407 | 100 | null |
1 | SIMPLE | h1 | null | eq_ref | PRIMARY | PRIMARY | 4 | my_schema.h.id | 1 | 100 | Using index |
id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
---|---|---|---|---|---|---|---|---|---|---|---|
1 | SIMPLE | h | null | index | PRIMARY | PRIMARY | 4 | null | 1407 | 100 | null |
1 | SIMPLE | h1 | null | eq_ref | PRIMARY | PRIMARY | 4 | my_schema.h.id | 1 | 100 | Using index |