Mysql Innerdb 索引失效场景。
本答案针对 mysql 的版本是 5.6.16-log 进行测试得出的。
假设有 index(a,b,c)
where 语句 | 索引是否被使用 |
---|---|
where a = 3 | 使用到了 a 索引 |
where a = 3 and b = 4 | 使用到了 a b 索引 |
where a = 3 and b = 4 and c= 5 | 使用到了 a,b,c索引 |
where a = ‘3’ (假设 a 是 int 类型) | 类型转换没有用到索引 |
where a = 3 and b >5 and c = 6 | b用到了范围,a 和 b 走索引,c没有走索引 |
where a = 3 and c = 5 | a 走索引,c 没有走索引 |
where a = 3 and b like ‘kk%’ and c = 4 | 使用到a和b, c在模糊查询的通配符之后,断了 |
where a = 3 or a=5 | 使用到了 or ,不走索引 |