mysql索引案例分析
表结构
order (oid,date,uid,status,money,time)
oid主键 date 普通索引 uid用户id 普通索引 status 普通索引
select * from order where status != 2
select * from order where status=0 or status=1
select * from order where status in(0,1)
select * from order where status = 0 union all select * from order where status = 1
结论:方案1最慢 , 2,3 ,4 都能够命中索引
union all 肯定能够命中索引 直接告诉mysql怎么做耗费cpu最少
简单in能够命中索引
对于or新版的mysql能够命中索引
对于!=负向查询不能命中索引