美文网首页
mysql执行计划中的extra字段

mysql执行计划中的extra字段

作者: 乔治m2 | 来源:发表于2019-12-18 17:15 被阅读0次

对于mysql的执行计划,主要是针对select查询优化而备的,通过在查询语句前加explain就可以显示此次查询的执行计划,当然查询计划中包括了id,select_type,type...字段,这里不逐一论述,主要是extra字段里面的字段进行解释。

create table user1(
id int not null primary key,
age int not null,
height int not null,
weight int not null
) engine=Innodb;

-----------------------
create index myindex on user1(age,height,weight);

extra字段存在的值

NULL: 没有用到额外的附加条件

Using filesort:查询语句中包含了oder by语句,索引无法完成排序,数据量小的时候在内存中完成排序,否者在磁盘中完成排序。

Using temporary:使用到了临时表。

Using Index:使用覆盖索引进行数据返回(Innodb引擎才存在),不会进行回表查找。

Using Where:查询语句中存在where范围查找,会回表查找数据。

Using Where Using Index:覆盖索引中存在范围查找,但是也不会进行回表,直接在索引上就能拿到数据。

Using Index Condition:跟Using Where Using Index有一些差别,它的查找用到了联合索引,查找的数据有不在索引中的字段,所以会进行回表查找数据。

具体sql

先往表中插入数据

insert into user1(id,age,height,weight,name) values(1,4,3,1,'小太'),(2,1,2,7,'小计'),(3,1,5,2,'小红'),(4,2,1,8,'小明'),(5,1,5,2,'小弄');

null情况

explain select * from user1;
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
|  1 | SIMPLE      | user1 | ALL  | NULL         | NULL | NULL    | NULL |    5 | NULL  |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+

Using Index

explain select age,height,weight,id from user1 where age = 2 and height = 1 and weight = 8;
+----+-------------+-------+------+---------------+---------+---------+-------------------+------+-------------+
| id | select_type | table | type | possible_keys | key     | key_len | ref               | rows | Extra       |
+----+-------------+-------+------+---------------+---------+---------+-------------------+------+-------------+
|  1 | SIMPLE      | user1 | ref  | myindex       | myindex | 15      | const,const,const |    1 | Using index |
+----+-------------+-------+------+---------------+---------+---------+-------------------+------+-------------+

Using Where Using Index

explain select age,height,weight,id from user1 where age = 2 and height > 1 and weight = 8;
+----+-------------+-------+------+---------------+---------+---------+-------+------+--------------------------+
| id | select_type | table | type | possible_keys | key     | key_len | ref   | rows | Extra                    |
+----+-------------+-------+------+---------------+---------+---------+-------+------+--------------------------+
|  1 | SIMPLE      | user1 | ref  | myindex       | myindex | 5       | const |    1 | Using where; Using index |
+----+-------------+-------+------+---------------+---------+---------+-------+------+--------------------------+

Using Index Condition

explain select age,height,weight,name from user1 where age = 2 and height > 1 and weight = 8;
+----+-------------+-------+-------+---------------+---------+---------+------+------+-----------------------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref  | rows | Extra                 |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-----------------------+
|  1 | SIMPLE      | user1 | range | myindex       | myindex | 10      | NULL |    1 | Using index condition |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-----------------------+

相关文章

  • Mysql优化

    MySQL 执行计划 主要就是关注字段 key type Extra key null 没有用索引...

  • mysql执行计划字段解释

    一、mysql执行计划表头 其中最重要的字段为:id、type、key、rows、Extra 二、各个字段的解释 ...

  • mysql执行计划中的extra字段

    对于mysql的执行计划,主要是针对select查询优化而备的,通过在查询语句前加explain就可以显示此次查询...

  • MySQL查询优化解读

    执行计划解释 执行计划字段解释 执行计划字段取值含意 TYPE KEY ROWS Extra 分页查询优化 原因分...

  • mysql执行计划explain type和extra

    mysql执行计划,搞定type和extra就能优化大部分sql了。type为主,extra为辅。 type: s...

  • MySQL explain extra

    MySQL执行计划中,extra可以展示执行的一些细节,比如索引下推,覆盖索引,排序等信息,为索引优化提供了更完整...

  • mysql 临时表

    EXPLAIN 执行计划中 Extra中有包含using temptable的话就会创建临时表。

  • MYSQL中常用的json函数

    比如extra字段格式化如下,下面有的例子会用到该Json 查询json中的某个字段 假如查询extra_json...

  • MySQL源码解析之执行计划

    MySQL源码解析之执行计划 MySQL执行计划介绍 MySQL执行计划代码概览 MySQL执行计划总结 一、My...

  • MYSQL执行计划字段详解

    Mysql查看执行计划 explain + sql :输出执行计划。explain extended + sql ...

网友评论

      本文标题:mysql执行计划中的extra字段

      本文链接:https://www.haomeiwen.com/subject/difenctx.html