#避免全表扫描
use test;
create table if not exists t(id int,num int defalult 0,name varchar(20));
create index ix_num on t(num);
#避免查询null
#未使用索引
select id from t where num=null;
#使用索引
select id from t where num=0;
#避免使用!=、<>(也是!=) 未使用索引
select * from t where num!=5;
select * from t where num<>5;
#避免使用or 未使用索引
select id from t where num=10 or num=20;
#使用索引
select id from t where num=10
union
select id from t where num=20;
-- 一个表的索引不超过6个