当前位置:网站首页>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.
边栏推荐
- Data Analysis 6
- pytest interface automation testing framework | pass in parameter values in the form of function return values
- rpm和yum
- STM32个人笔记-程序跑飞
- MySQL query advanced - from the use of functions to table joins, do you remember?
- PerViT: 神经网络也能像人类利用外围视觉一样观察图像!
- HoloView 在 jyputer lab/notebook 不显示总结
- UXDB如何返回当前数据库所有表的记录数?
- Data Analysis 5
- Chapter 9 of Huawei Deep Learning Course - Convolutional Neural Network and Case Practice
猜你喜欢
随机推荐
zip package all files in the directory (including hidden files/folders)
Idea common plugins
2022.7.31-----leetcode.1161
Analysis of High Availability Solution Based on MySql, Redis, Mq, ES
The soul asks: How does MySQL solve phantom reads?
Leetcode - 6135: the longest part of the figure
STM32个人笔记-看门狗
How to get page data
2022杭电中超杯(1)个人题解
Pod environment variables and initContainer
HoloView -- Tabular Datasets
巧妙利用unbuffer实时写入
自定义IP在PCIE中使用
Parsing MySQL Databases: "SQL Optimization" vs. "Index Optimization"
STM32个人笔记-程序跑飞
[Tear AHB-APB Bridge by hand]~ Why aren't the lower two bits of the AHB address bus used to represent the address?
TiDB的真实数据库数据是存在kv和还是pd上?
微服务:事务管理
codeforces每日5题(均1600)-第二十七天
消息队列面试题(2022最新整理)