当前位置:网站首页>Explanation of each column output by explain statement
Explanation of each column output by explain statement
2022-06-11 20:50:00 【Pig man blogs】
# EXPLAIN Statement output column interpretation
| Name | describe |
|---|---|
| id | In a large query statement, each SELECT Each keyword corresponds to a unique id |
| select_type | SELECT The type of query corresponding to the keyword |
| table | Table name |
| partitions | Matching partition information |
| type | Access methods for single tables |
| possible_keys | Possible indexes |
| key | Index actually used |
| key_len | The actual index length used |
| ref | When using index column equivalent queries , Information about the object matching the index column |
| rows | Estimated number of records to read |
| filtered | The percentage of records remaining after a table is filtered by search criteria |
| Extra | Some extra information |
# select_type
every last SELECT The small queries represented by keywords have a definition called select_type Properties of , It means we As long as you know about a small query select_type attribute , You know what role this small query plays in the whole big query

# SIMPLE
The query statement does not contain UNION Or subquery queries are counted as SIMPLE type , Join query is also SIMPLE type .
# PRIMARY
To contain UNION 、 UNION ALL Or for a large subquery , It's made up of a few small queries , The leftmost query Of select_type The value is PRIMARY

# UNION
To contain UNION perhaps UNION ALL For big queries , It's made up of a few small queries , Except for the little query on the left Outside , The rest of the small queries are select_type The value is UNION
# UNION RESULT
MySQL Choose to use a temporary table to complete UNION Query de duplication work , For the query of the temporary table select_type Namely UNION RESULT , The example above has , I won't go into that .
# SUBQUERY
If the query statement containing the subquery cannot be converted to the corresponding semi-join In the form of , And the subquery is an unrelated subquery , And the query optimizer decides to use the sub query
Query materialized scheme to execute this sub query , The first... Of the subquery SELECT The query represented by the keyword select_type Namely SUBQUERY
# DEPENDENT SUBQUERY
If the query statement containing the subquery cannot be converted to the corresponding semi-join In the form of , And the subquery is a related subquery , Then this sub query One of the first SELECT The query represented by the keyword select_type Namely DEPENDENT SUBQUERY
# DEPENDENT UNION
Include in UNION perhaps UNION ALL In the big query , If each small query depends on the outer query , Except for the little query on the far left , The rest of the small queries are select_type The value is DEPENDENT UNION
# DERIVED
For queries containing derived tables that are materialized , The derived table corresponds to the select_type Namely DERIVED
# MATERIALIZED
When the query optimizer executes a statement that contains subqueries , Select materialize the sub query and connect it with the outer query , Corresponding to this subquery select_type The attribute is MATERIALIZED
# UNCACHEABLE SUBQUERY
Not commonly used , Don't nag more .
# UNCACHEABLE UNION
Not commonly used , Don't nag more .
# type
A record of the implementation plan represents MySQL Access method when executing query on a table
system: When there is only one record in the table and the statistics of the storage engine used by the table are accurate , such as MyISAM、Memory, So the way to access the table is system.
const: Match constants by primary key or unique secondary index column
eq_ref: When connecting queries , If Driven tables are accessed by matching primary keys or unique secondary index columns Of ( If the primary key or unique secondary index is a federated index , All index columns must be compared for equivalence ), Then it's right to Access method of driven table Namely eq_ref
ref: The search condition is that the secondary index column is compared with the constant equivalence Locate multiple records , An access method that uses secondary indexes to execute queries
fulltext Full-text index
ref_or_null: When performing an equivalent matching query on a common secondary index , The value of the index column can also be NULL When the value of , Then the access method to the table might be ref_or_null
index_merge: In general, only one index can be used for a table query , However, when we nag about the single table access method, we specially emphasize that it can be used in some scenarios Intersection 、 Union 、 Sort-Union These three indexes are combined And execute the query , Multiple indexes will be used .
unique_subquery: Be similar to Of the driven table in a two table connection eq_ref Access method , unique_subquery yes For some include IN Subquery In the query statement of , If the query optimizer decides to IN The subquery is converted to EXISTS Subquery , and Subqueries can use the primary key for equivalent matching Words , Then the subquery execution plan is type The value of the column is unique_subquery
index_subquery: index_subquery And unique_subquery similar , The only way to access the tables in the subquery is to use Ordinary index (unique_subquery Previously, the primary key index or primary and secondary indexes were used ).
range: If you use an index to get some Range interval The record of , Then it's possible to use range Access method
index: When we can use index overlay , But when you need to scan all index records , The access method of this table is index.
ALL: Full table scan .
# possible_keys and key
possible_keys The list is shown in a query statement , What are the indexes that may be used to perform a single table query on a table , key The list shows which indexes are actually used .
# key_len
key_len The list shows when the optimizer decides to execute a query using an index , The maximum length of the index record , It consists of these three parts :
- For index columns with fixed length types , The maximum length of the storage space actually occupied by it is the fixed value , For variable length index columns of the specified character set , For example, the type of an index column is VARCHAR(100) , The character set used is utf8 , Then the maximum storage space actually occupied by this column is 100 × 3 = 300 Bytes .
- If the index column is used to store NULL value , be key_len Can't store NULL When the value is more 1 Bytes .
- For variable length fields , There will be 2 A space of bytes to store the actual length of the variable length column .
Example

Tips : Some students may have questions : You nag ahead InnoDB Line format does not mean , It is not possible to store the actual length of the variable length field 1 Bytes or 2 Byte? ? Why now
No matter three, seven, twenty-one are used 2 Bytes ? The point to be emphasized here is , The execution plan is generated in MySQL server Functions in the layer , It is not specific to the functions of a specific storage engine , Design
MySQL My uncle outputs... In the execution plan key_len Column The main purpose is to distinguish the specific index columns used in a query using a joint index , It is not for the sake of accurate explanation
The storage engine stores the actual length of the variable length field. What space does it occupy 1 Two bytes or 2 Bytes
# ref
# rows
If the query optimizer decides to perform a query on a table using a full table scan , Implementation plan rows The column represents the expected number of rows to scan , If an index is used to execute a query , Implementation plan rows The column represents the number of index record rows to be scanned
# filtered
When analyzing the cost of connection query, I put forward a condition filtering The concept of , Namely MySQL A strategy used when calculating the fan out of the driving table :
- If you use a single table query executed by full table scanning , When calculating the fan out of the drive table, you need to estimate how many records meet the search conditions .
- If an index is used, perform a single table scan , When calculating the fan out of the driving table, you need to estimate how many records meet the search conditions other than the search conditions of the corresponding index .
Connect the execution plan records corresponding to the drive table in the query filtered value , For example, the following query :

You can see from the execution plan , The query optimizer intends to s1 As a driver table , s2 As driven tables . We can see the driver table s1 The execution plan of the table rows As a 9688 , filtered As a 10.00 , That means driving tables s1 The fan out value of is 9688 × 10.00% = 968.8 , This means that we have to perform about 968 Queries .
Extra Columns are used to illustrate some additional information , We can use this additional information to understand more accurately MySQL How the given query statement will be executed
Welcome to your attention ggball Blog !
边栏推荐
- On scale of canvas recttransform in ugui
- Gestionnaire de paquets d'Unit é Starting Server Stuck
- [nk] 牛客练习赛100 C 小红的删数字
- 为什么100G网络传输要使用iWARP、RoCE v2、NVMe-oF等协议
- 【计算机推免】哈尔滨工业大学物联网与泛在智能研究中心面向全国高校推免生招收2023级研究生(硕、博、直博生)
- 28. JS执行机制
- The input value "18-20000hz" is incorrect. The setting information is incomplete. Please select a company
- File upload vulnerability - simple exploitation 2 (Mozhe college shooting range)
- Volcano engine, Alibaba cloud and Tencent cloud jointly released the 'ultra low delay' live broadcast technical standard
- Ubantu1804 two opencv versions coexist
猜你喜欢

周刊02|不瞒你说,我其实是MIT的学生

A mechanics informed artistic neural network approach in data driven constructive modeling

29. location對象

频域滤波器

Rtd2171u, substitute for trd2171u, substitute for trd2171u, cs5261 C to hdmi4k_ 30Hz
![[data visualization] Apache superset 1.2.0 tutorial (II) - Quick Start (visualizing King hero data)](/img/21/c2212a674fdf77571305446217a5ca.png)
[data visualization] Apache superset 1.2.0 tutorial (II) - Quick Start (visualizing King hero data)

【数据可视化】使用 Apache Superset 可视化 ClickHouse 数据

输入值“18-20000hz”错误,设置信息不完整,请选择单位

unity package manager starting server stuck(Unity啟動卡在starting server,然後報錯)

使用flask框架写挡板
随机推荐
Black circle display implementation
Ubantu1804 two opencv versions coexist
The input value "18-20000hz" is incorrect. The setting information is incomplete. Please select a company
修改本地微信小程序的AppID
Research and Analysis on the market status of polybutene-1 in China from 2021 to 2027 and forecast report on its development prospect
Text to speech small software
7905 and TL431 negative voltage regulator circuit - regulator and floating circuit relative to the positive pole of the power supply
Using the flask framework to write the bezel
Application scenario: wide application of Poe network card in NDI technology for live broadcast program production
12 date and time in R
c语言程序设计知识点总结 01
Final examination of Dialectics of nature 1
2022-2028 global and Chinese thermopile detector Market Status and future development trend
Vectordrawable error
26. timer
php pcntl_fork 创建多个子进程解析
Première formation sur les largeurs modernes
Chrome V8 source code 48 The secret of weak type addition,'+'source code analysis
UI automated interview questions
【数据可视化】Apache Superset 1.2.0教程 (二)——快速入门(可视化王者英雄数据)