有表及索引如下:create table tbl(a int, b int);
create index indx on tbl(a);
对于下列语句,1. select * from tbl order by a desc;
2. select * from tbl where b > 100 order by a desc;
对于语句1而言,索引indx可以起到作用,
但是对于多了一个条件判断的语句2而言,是不是就没有啥效果了?
因为,要先找到b>100的所有记录,然后再对他们进行排序,这个时候,indx并不会起到什么好的作用!
create index indx on tbl(a);
对于下列语句,1. select * from tbl order by a desc;
2. select * from tbl where b > 100 order by a desc;
对于语句1而言,索引indx可以起到作用,
但是对于多了一个条件判断的语句2而言,是不是就没有啥效果了?
因为,要先找到b>100的所有记录,然后再对他们进行排序,这个时候,indx并不会起到什么好的作用!
不知道我的观点是否正确?
否则,则需要穷尽全表,得到所需,再去filesort.