84669 personnes étudient
152542 personnes étudient
20005 personnes étudient
5487 personnes étudient
7821 personnes étudient
359900 personnes étudient
3350 personnes étudient
180660 personnes étudient
48569 personnes étudient
18603 personnes étudient
40936 personnes étudient
1549 personnes étudient
1183 personnes étudient
32909 personnes étudient
如果test表有一个组合索引(a,b),执行如下两条语句。explain select * from test where a=1 and b=1;explain select * from test where b=1 and a=1;执行结果显示这两条语句都用索引。根据最左原则,只有第一条使用索引,第二条不使用索引。不明白为什么,求解惑
题主列出的情况,mysql会优化where子句的条件顺序,让查询符合索引顺序。
更具体点,上面的sql属于交集查询(都是and),在mysql中会使用Index Merge intersection algorithm算法来调整条件子句顺序。更详细的解释参见官方文档。
Index Merge intersection algorithm
题主列出的情况,mysql会优化where子句的条件顺序,让查询符合索引顺序。
更具体点,上面的sql属于交集查询(都是and),在mysql中会使用
Index Merge intersection algorithm
算法来调整条件子句顺序。更详细的解释参见官方文档。