当前位置:网站首页>Explain / Desc execution plan analysis
Explain / Desc execution plan analysis
2022-08-01 09:24:00 【Eat well without getting fat】
Simple Instructions
In MySQL, both explain
and desc
can generate information about SQL execution by the optimizer, so no matter which one is used, the result is the same, this article only usesdesc
for description.
The following is a query statement and the corresponding SQL execution plan:
As can be seen from the figure, the SQL execution plan shows 12element information.
id
The first is id
, which indicates the execution order of the operation table of the select
statement.
The larger the value of id
, the higher the priority.
When id
is the same, it is generally executed in order from top to bottom, but it is determined by the optimizer.
When the id
is different, there may be nested sub-queries, and the sub-queries have higher priority and are executed first.
select_type
The second is select_type
, which distinguishes between different query types, including SIMPLE
, PRIMARY
, SUBQUERY
, DERIVED
, UNION
, UNION RESULT
.
SIMPLE--Simplest query, excluding subqueries and intersection unions.PRIMARY-- contains subsections, the outermost is PRIMARY.SUBQUERY-- select or where contains a subqueryDERIVED-- Subquery after from ; If UNION is after from, the outermost layer is DERIVEDUNION-- the select statement after union is UNION
table
The third one is the table name.
may also be a temporary table, an alias for a table.
partitions
The fourth represents the partition information of the query table.
null if there is no partitionIf there is a partition, the partition status will be displayed
type
The fifth shows the type of query, reflecting the difference in performance.
The performance of SQL optimization from good to bad is as follows:system > const > eq_ref > ref > ref_or_null > index_merge > unique_subquery > index_subquery > range > index >ALL
1) system: There is only one row of records in the table, the amount of data is very small, and no disk IO is required
2) const: Hit the primary key or hit the unique index or hit a constant value when querying.The at most one matching line.
3) eq_ref: Same as const usage.The difference is that eq_ref is used for join table queries (composed of a row).
4) ref: Compared with eq_ref, a non-unique index can be used, and multiple rows of query results will be returned.
5) ref_or_null: Compared with ref, the query result returns a value containing null
.
6) index_merge: Index merge optimization, use more than two indexes when querying.
7) unique_subquery: replace the IN
subquery, which returns unique values.
8) index_subquery: Different from unique_subquery, it is used for non-unique indexes and can return duplicate values.
9) range: For the index field, query the rows of a given range.Generally, where
is followed by bettween...and, <,>, <=, in
and other conditional queries
10) index: traverse the index tree and perform a full table scan.
11) all: read from the hard disk, full table scan.
possible_keys
The sixth means that all indexes contained in this field will be listed, but these indexes will not necessarily go in the end.
key
The seventh represents the index actually used.
key_len
The eighth indicates the index length (in bytes) used by the query. The shorter the index, the better the performance.
Only the index length of the where condition column is calculated, and the index of the sorting and grouping statements is not counted.
ref
The ninth indicates the column that the index is used for.
When using constant equivalent query, display const,When the query is related, the related fields of the corresponding related table will be displayedIf the query condition uses an expression, function, or the condition column is internally implicitly converted, it may be displayed as funcOtherwise it shows null
rows
The tenth indicates that the system estimates the number of lines that should be read to find the desired result.
The smaller the value, the better the performance.
filtered
The eleventh indicates the percentage of record data in the table that meet the conditions.
Extra
The twelfth represents additional information that cannot be displayed in the first eleven columns.
1) Using index: Covering index is used.
2) Using where: The query does not go through the index, and the corresponding result set is matched through the where condition.
3) Using temporary: The results of the query are stored in a temporary table, usually sorted or grouped.
4) Using filesort: The sorting operation cannot be completed with an index. The ORDER BY
field has no index and needs to be optimized.
5) Impossible where: The desired result could not be found due to an incorrect where statement.
6) No tables used: There is no from statement.
边栏推荐
猜你喜欢
随机推荐
优炫数据库支持Oracle哪几种时间及日期类型
杰理AD14N/AD15N---串口中断问题
ACmix 论文精读,并解析其模型结构
leetcode-6132: Make all elements in array equal to zero
Prime Ring Problem
scrapy爬虫框架的使用
用OpenCV的边缘检测
力扣周赛304 6135. 图中的最长环 内向基环树
Leetcode - 6135: the longest part of the figure
Redis middleware (from building to refuse pit)
179. 最大数
HoloView 在 jyputer lab/notebook 不显示总结
JVM内存模型之深究模型特征
A problem with writing to the database after PHP gets the timestamp
Static Pod, Pod Creation Process, Container Resource Limits
Ogg synchronizes oracle to mysql, there may be characters that need to be escaped in the field, how to configure escape?
STM32个人笔记-看门狗
巧妙利用unbuffer实时写入
sqlserver怎么查询一张表中同人员的交叉日期
基于tika实现对文件类型进行判断