MySQL的索引分类和失效情况
索引分类
唯一索引
普通索引
全文索引
主键索引
空间索引
复合索引
索引失效情况
列和列做对比(两列都设置了索引)
select * from test where id=c_id;
存在NULL值条件
select * from test where `name` is not null;
not条件、not in 条件、<> 、 not exists
select * from test where id <> 500;
like查询,使用前%
select * from test where name like '%张%';
查询条件上对索引列进行函数运算,如:to_char、to_date、to_number、trunc
select * from test where upper(name)='SUNYANG';
数据类型不一样,比如表里索引列是int类型,查询是带字符串
select * from sunyang where id='123';
对索引列进行运算操作
select * from sunyang where money/2=300;
ps: 当表的数据比较少的时候,MySQL会判断走全表扫描速度比走索引速度快时,MySQL会选择使用全表扫描,此时索引会失效。
特别感谢
本作品采用《CC 协议》,转载必须注明作者和本文链接