order by主要优化出现filesort的情况,以下情况可以使用索引.
1.order by 字段都来自驱动表且满足索引的最左前缀. select a from test order by a,b
2.当order by字段不是最左前缀时,如果字段前的字段为常量则可以利用. select a from test where a = 3 order by b
3.当order by字段排序顺序与索引排序顺序一致或相反时可以利用. select a,b from test order by a DESC,b DESC. 或 select a,b from test order by a,b;
PS:test表已有索引index(a,b)