数据库
首页 > 数据库> > Explain查询MySQL执行计划

Explain查询MySQL执行计划

作者:互联网

用 explain 来优化查询

explain 语句能够提供 MySQL 执行语句的信息,即语句的执行计划

explain 支持的语句有:

explain 对 select 语句的输出格式:(官网: https://dev.mysql.com/doc/refman/5.7/en/explain-output.html

详解 explain 输出的信息

id: 查询的标识符,即查询语句中每个 select 的顺序号。值可以为null,当前行引用的是其它行的并集(union)结果。

select_type: select的类型

table: 表名,即 explain 输出的行所引用的表名,也可以是下面的值:

partitions: 匹配的分区,即被查询匹配上的记录所在的分区,表没有分区的话就是 null

type: 连接类型(官网: https://dev.mysql.com/doc/refman/5.7/en/explain-output.html#explain-join-types

小结

1、就查效率来说:system > const > eq_ref > ref > range > index > all
2、index merge 是个坑,因为加太多索引的情况,全并索引的结果会开销比较大,还不如全表扫描。

标签:union,Explain,查询,索引,subquery,MySQL,--,select
来源: https://www.cnblogs.com/rollo-tan/p/16115128.html