... WHERE index_part1=1 AND index_part2=2 AND other_column=3
/* index = 1 OR index = 2 */
... WHERE index=1 OR A=10 AND index=2
/* 优化成 "index_part1='hello'" */
... WHERE index_part1='hello' AND index_part3=5
/* 可以使用 index1 的索引但是不会使用 index2 和 index3 */
... WHERE index1=1 AND index2=2 OR index1=3 AND index3=3;
下面的WHERE条件不会使用索引:
复制代码 代码如下:
/* index_part1 没有被使用到 */
... WHERE index_part2=1 AND index_part3=2
/* 索引 index 没有出现在每个 where 子句中 */
... WHERE index=1 OR A=10
/* 没有索引覆盖所有列 */
... WHERE index_part1=1 OR index_part2=10