mysql查询优化和参数优化

#避免全表扫描
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个

 

posted @ 2022-04-30 22:30  森林深处有一道光  阅读(48)  评论(0)    收藏  举报