问题遇到的现象和发生背景
想问一下博主,我在使用过程中遇到的一个问题
组合索引为什么有时候是走的有时候却不走组合索引,特别是在使用where的时候,望解答
想问一下博主,我在使用过程中遇到的一个问题
组合索引为什么有时候是走的有时候却不走组合索引,特别是在使用where的时候,望解答
索引失效的方式很多,组合索引符合最左原则 ,可以看下下边这个例子
index(a,b,c)
where a=3 只使用了a
where a=3 and b=5 使用了a,b
where a=3 and b=5 and c=4 使用了a,b,c
where b=3 or where c=4 没有使用索引
where a=3 and c=4 仅使用了a
where a=3 and b>10 and c=7 使用了a,b
where a=3 and b like 'xx%' and c=7 使用了a,b
其实相当于创建了多个索引:key(a)、key(a,b)、key(a,b,c)