where条件字段可以设置索引吗

where条件字段可以设置索引吗

假设有组合索引 index(a,b,c),以下情况不考虑 select * 内容 (覆盖索引)

where a = 3 用到索引 a

where a = 3 and b = 3 用到索引 a,b

where a = 3 and b = 4 and c = 5 用到索引 a,b,c

where b = 3 或者 where b = 3 and c = 4 或者 where c = 4 索引失效

where a = 3 and c = 5 用到索引 a

where a = 3 and b > 4 and c = 5 用到索引a和b,c不能用在范围之后

where a = 3 and b like 'kk%' and c = 4 用到索引a,b,c。

where a = 3 and b like '%kk' and c = 4 使用到 a

where a = 3 and b like '%kk%' and c = 4 用到 a

where a = 3 and b like 'k%kk%' and c = 4 用到a,b,c

切记使用索引字段值的类型必须匹配,否则索引无效。