我的主要来自于自学,如果有错请指正
建表
create table test_index(id int not null primary key,a char(4),b char(4),c char(4));
创建索引
create index index_a_b_c on test_index(a,b,c);
通过对不同字段order by对比
Extra 字段使用Using index
explain select * from test_index order by a;
explain select * from test_index order by a,b;
explain select * from test_index order by a,b,c;
Extra 字段使用Using filesort
explain select * from test_index order by b;
explain select * from test_index order by c;
explain select * from test_index order by b,c;
explain select * from test_index order by a,c;
总结
在order by关键字中使用索引时注意,和创建索引的顺序关联起来
比如创建索引a_b_c
查询的话要使用到索引的排序按照顺序就是
a
a、b
a、b、c
才可以