MySQL版本:
表结构:
SQL:
create INDEX idx_a on t(a);
create INDEX idx_e on t(e);
Alter table t ADD INDEX idx_b_c (b,c)
ALter table t Add INDEX idx_b_c_d (b,c,d)
show INDEX FROM t;
drop index a on t ;
explain SELECT * from t where id='id' or e ='e'; # all nokey, 有的博主写的会走索引
explain SELECT * from t where id='id' and e ='e'; # const PRIMARY
explain SELECT * from t where a='a' OR b ='b'; # all nokey
explain SELECT * from t where a='a' AND b ='b'; # ref idx_a
explain SELECT * from t where a='a' AND b ='b' or c='c'; # all nokey
explain SELECT * from t where b ='b' OR c ='c'; # all nokey
explain SELECT * from t where b ='b' OR d ='d'; # all nokey
总结:where中包含了or都不会走索引