-
#避免全表扫描
-
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;
查询,索引优化
最新推荐文章于 2024-07-11 20:24:07 发布