我是靠谱客的博主 大气猫咪,这篇文章主要介绍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个

最后

以上就是大气猫咪最近收集整理的关于mysql查询优化和参数优化的全部内容,更多相关mysql查询优化和参数优化内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(144)

评论列表共有 0 条评论

立即
投稿
返回
顶部