当前位置:网站首页>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 UNIONtable
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 displayedtype
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 >ALL1) 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 nullrows
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.
边栏推荐
- 扁平数组转树结构实现方式
- Intensive reading of ACmix papers, and analysis of its model structure
- 笔记。。。。
- 解析MySQL数据库:“SQL优化”与“索引优化”
- 基于MySql,Redis,Mq,ES的高可用方案解析
- sqlserver 对比两张表的差异
- leetcode-6134:找到离给定两个节点最近的节点
- Chapters 6 and 7 of Huawei Deep Learning Course
- 22 Niu Ke Duo School 1 I. Chiitoitsu (Probability dp)
- navicat mysql 内存占用过高,被强制关闭
猜你喜欢

HoloView——实时数据

Parsing MySQL Databases: "SQL Optimization" vs. "Index Optimization"

opencv创建窗口—cv.namedWindow()

leetcode-6133:分组的最大数量

HoloView--Customization

将Servlet项目改为SSM项目

YOLOv7-Pose尝鲜,基于YOLOv7的关键点模型测评
![[Tear AHB-APB Bridge by hand]~ Why aren't the lower two bits of the AHB address bus used to represent the address?](/img/fb/c95c5857024db001638cd484c5e78f.png)
[Tear AHB-APB Bridge by hand]~ Why aren't the lower two bits of the AHB address bus used to represent the address?

22 Grab the Seat 1 C.Grab the Seat (Geometry + Violence)

Data Analysis 5
随机推荐
【STM32】入门(一):环境搭建、编译、下载、运行
Pytest | skip module interface test automation framework
指针的介绍及应用
GBase 8c中怎么查询数据库配置参数,例如datestyle
Shell:条件测试操作
GO error handling
STM32个人笔记-程序跑飞
leetcode 42. 接雨水
Static Pod, Pod Creation Process, Container Resource Limits
How to ensure the consistency of database and cache data?
将aof文件转换为命令waoffle安装和使用
最新的Cesium和Three的整合方法(附完整代码)
Microsoft Azure & NVIDIA IoT 开发者季 I|Azure IoT & NVIDIA Jetson 开发基础
net stop/start mysql80 access denied
Intensive reading of ACmix papers, and analysis of its model structure
various network protocols
Data Analysis 5
How to get page data
自定义IP在PCIE中使用
PHP获取时间戳后写数据库的一个问题