上一篇 <<<MySQL常用命令汇总
下一篇 >>>MySQL性能优化之慢查询定位
执行命令
优化目标:type字段要达到range级别,最好是ref级别
1.id:序列号
2.select_type:表示查询的类型
3.table:执行计划访问的表
4.partitions 匹配的分区
5.type:表的连接类型
explain select * from jarye_student where id = 1;
explain select * from jarye_student_class left join jarye_class on jarye_student_class.class_id = jarye_class.id;
explain select * from jarye_class where name = "第一期";
explain select * from jarye_class;
explain select * from jarye_student; // 查询结果有不含索引的字段,则查询全表
explain select id from jarye_student;---若有具体的列,且都在索引中,则会直接走索引
6.possible_keys:表示查询时,可能使用的索引
7.key:实际使用的索引
8.key_len:索引字段的长度
explain select * from jarye_student_class where class_id=1
explain select * from jarye_student_class where class_id=1 and student_id=1;
9.ref:列与索引的比较
10.rows:扫描出的行数(估算的行数)
11.filtered:按表条件过滤的行百分比
12.Extra:附加信息
explain select class_id,id from jarye_student_class where class_id='1';
explain select * from employees where name= 'jarye' and position ='ceo' order by age;
explain select name,age from employees where name= 'jarye' and position ='ceo' order by age;
//查询的列未被索引覆盖,where筛选条件非索引的前导列
explain select class_id,id,remark from jarye_student_class where remark='aaa';
explain select * from jarye_student order by name ;
推荐阅读:
<<<MySQL性能优化之慢查询定位
<<<MySQL性能优化之表设计优化
<<<MySQL性能优化之常用SQL语句优化
<<<MySQL性能优化之索引调优实战
<<<MySQL性能优化之分页查询优化
<<<MySQL性能优化之关联查询优化
<<<MySQL性能优化之in、exists优化
<<<order by中的单路和双路排序算法原理
<<<MySQL如何性能优化面试题完美解答