0
点赞
收藏
分享

微信扫一扫

mysql 查询优化 索引优化

彭维盛 2022-05-01 阅读 122
sql
#避免全表扫描
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;
举报

相关推荐

0 条评论