mysql EXPLAIN命令的输出列简介

MySQL :: MySQL 8.2 Reference Manual :: 8.8.2 EXPLAIN Output Format

explain命令提供了mysql数据库如何执行SQL语句的信息,可以跟 SELECTDELETEINSERTREPLACEUPDATE, 和 TABLE一起使用。 

explain命令可能输出多行,每行涉及一个表 。

先来看一个实际的执行,假设执行explain select * from test_table where type='register';输出如下:

explain命令输出的列如下:

Table 8.1 EXPLAIN Output Columns

ColumnJSON NameMeaning
idselect_idThe SELECT identifier
select_typeNoneThe SELECT type
tabletable_nameThe table for the output row
partitionspartitionsThe matching partitions
typeaccess_typeThe join type
possible_keyspossible_keysThe possible indexes to choose
keykeyThe index actually chosen
key_lenkey_lengthThe length of the chosen key
refrefThe columns compared to the index
rowsrowsEstimate of rows to be examined
filteredfilteredPercentage of rows filtered by table condition
ExtraNoneAdditional information
  • id :select的标识符。
  • select_type:select的类型,取值如下:
elect_type ValueJSON NameMeaning
SIMPLENoneSimple SELECT (not using UNION or subqueries)
PRIMARYNoneOutermost SELECT
UNIONNoneSecond or later SELECT statement in a UNION
DEPENDENT UNIONdependent (true)Second or later SELECT statement in a UNION, dependent on outer query
UNION RESULTunion_resultResult of a UNION.
SUBQUERYNoneFirst SELECT in subquery
DEPENDENT SUBQUERYdependent (true)First SELECT in subquery, dependent on outer query
DERIVEDNoneDerived table
DEPENDENT DERIVEDdependent (true)Derived table dependent on another table
MATERIALIZEDmaterialized_from_subqueryMaterialized subquery
UNCACHEABLE SUBQUERYcacheable (false)A subquery for which the result cannot be cached and must be re-evaluated for each row of the outer query
UNCACHEABLE UNIONcacheable (false)The second or later select in a UNION that belongs to an uncacheable subquery (see UNCACHEABLE SUBQUERY)
  • table :这一行的输出涉及的表名 。
  • partitions :查询从哪个分区匹配到的记录。如果不是分区表,那么该返回的值为NULL。
  • type :join 类型。各种类型的解释请参考https://dev.mysql.com/doc/refman/8.2/en/explain-output.html#explain-join-types
  • possible_keys:一个索引列表,mysql可以从其中选择索引,来找到要查询的行。
  • key :mysql最终决定使用的索引。
  • key_len :mysql最终决定使用的索引的长度。
  • ref :使用key 列指定的索引,找到要查询的记录,用哪些列或者常数跟索引进行比较。
  • rows :mysql认为它找到要查找的记录所要遍历的行数。
  • filtered :用表的条件过滤表的行数据的百分比,最大值是100。
  • Extra :包含了mysql如何解析查询的额外信息。各种取值请参考:MySQL :: MySQL 8.2 Reference Manual :: 8.8.2 EXPLAIN Output Format

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值