索引: create index idx_stuno_name_age on student(stuno,name,age);
查询分析:
mysql> explain select * from student where name='abc' order by stuno limit 10;
+----+-------------+---------+------------+-------+---------------+--------------------+---------+------+------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+---------+------------+-------+---------------+--------------------+---------+------+------+----------+-------------+
| 1 | SIMPLE | student | NULL | index | NULL | idx_stuno_name_age | 72 | NULL | 10 | 10.00 | Using where |
+----+-------------+---------+------------+-------+---------------+--------------------+---------+------+------+----------+-------------+
1 row in set, 1 warning (0.00 sec)
按照sql的执行顺序,应该是先执行where然后执行order by,然后索引的顺序为(stuno,name,age),这样不遵循最左前缀原则啊,想请教为什么还是能用上索引?