84669 Lernen von Personen
152542 Lernen von Personen
20005 Lernen von Personen
5487 Lernen von Personen
7821 Lernen von Personen
359900 Lernen von Personen
3350 Lernen von Personen
180660 Lernen von Personen
48569 Lernen von Personen
18603 Lernen von Personen
40936 Lernen von Personen
1549 Lernen von Personen
1183 Lernen von Personen
32909 Lernen von Personen
如果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
算法来调整条件子句顺序。更详细的解释参见官方文档。