当前位置:网站首页>Explanation keyword of MySQL
Explanation keyword of MySQL
2022-04-23 03:17:00 【Xiaodaoxian 97】
In this paper, from :
List of articles
One 、 Start
When one SQL Query is slow , Want to see this SQL When implementing , We can use explain Key words to SQL Analyze .
Use explain keyword , It will return a result , There are 12 A field , Each field identifies a meaning , We analyze it according to its meaning .

| key | desc |
|---|---|
| id | select The serial number of the query , Contains a set of numbers , Represents execution in a query select The order of clauses or operation tables |
| select_type | Query type |
| table | Which table is being visited |
| partitions | Matching partition |
| type | Type of visit |
| possible_keys | Show the indexes that may be applied to this table , One or more , But it doesn't necessarily apply to |
| key | Index actually used , If NULL, No index is used |
| key_len | Represents the number of bytes used in the index , You can use this column to calculate the length of the index used in the query |
| ref | Shows which column of the index is used , If possible , It's a constant , Which columns or constants are used to find... On indexed columns |
| rows | According to table statistics and index selection , Roughly estimate the number of rows to read to find the required record |
| filtered | The percentage of table rows queried in the table |
| Extra | Contains additional information that is not suitable for display in other columns but is important |
Two 、 Field meaning
2-1、id
-
id Phase at the same time , The order of execution is from top to bottom
-
If it's a subquery ,id The serial number of will increase ,id The higher the value, the higher the priority , The first to be executed
-
id If the same , It can be thought of as a group , From top to bottom ; In all groups ,id The bigger the value is. , The higher the priority , Execute first
2-2、select_type
Each select The type of clause
| key | desc |
|---|---|
| SIMPLE | Simple SELECT, Don't use UNION Or subquery, etc |
| PRIMARY | The outermost query in the subquery , If the query contains any complex sub parts , The outermost select Marked as PRIMARY |
| UNION | If the second select Appear in the uion after , Is marked as UNION |
| DEPENDENT UNION | UNION The second or later of SELECT sentence , Depends on external queries |
| UNION RESULT | UNION Result ,UNION The second... In the sentence SELECT Start all the back SELECT |
| SUBQUERY | First in subquery SELECT, The results don't depend on external queries |
| DEPENDENT SUBQUERY | First in subquery SELECT, Depends on external queries |
| DERIVED | Derived from table SELECT, FROM A subquery of a clause |
| UNCACHEABLE SUBQUERY | The result of a subquery cannot be cached , The first line of the outer link must be reevaluated |
2-3、table
Show the table names in the database accessed in this step ( Show which table this row's data is about ), Sometimes it's not a real name , It could be an alias .
2-4、partitions
Matching partition
2-5、type
How to access the table , Express MySQL How to find the desired row in the table , also called Access type
Common types are : ALL、index、range、 ref、eq_ref、const、system、NULL( From left to right , Performance from poor to good )
| key | desc |
|---|---|
| ALL | Full Table Scan, Will traverse the entire table to find the matching row |
| index | Full Index Scan,index And ALL The difference for index Type only traverses the index tree |
| range | Retrieve only rows in the given range , Use an index to select rows |
| ref | Non unique index scan , Returns all rows that match a single value |
| eq_ref | similar ref, The difference is that the index used is the only index , For each index key value , Only one record in the table matches , Simply speaking , It is used in multi table connection primary key perhaps unique key As a condition of Association |
| const、system | When MySQL Optimize some part of the query , And convert to a constant , Use these types to access . For example, place the primary key in where In the list ,MySQL You can convert the query to a constant ,system yes const Special case of type , When the query table has only one row , Use system |
| NULL | MySQL Decompose statements during optimization , Execute without even accessing tables or indexes , For example, selecting the minimum value from an index column can be done through a separate index search . |
2-6、possible_keys
Show the indexes that may be applied to this table , One or more . If there is an index in the field involved in the query , Then the index will be listed , But it doesn't have to be used .
2-7、key
key Columns show MySQL Actually decide which key to use ( Indexes ), Must be included in possible_keys in
2-8、key_len
Represents the number of bytes used in the index , You can use this column to calculate the length of the index used in the query (key_len The displayed value is the maximum possible length of the index field , It's not the actual length , namely key_len It is calculated according to the table definition , It is not retrieved from the table )
Without loss of accuracy , The shorter the length, the better
2-9、ref
Shows which column of the index is used , If possible , It's a constant , Which columns or constants are used to find values on index columns
2-10、rows
According to table statistics and index selection , Roughly estimate the number of rows to read to find the required record
2-11、filtered
The percentage of table rows queried in the table
2-12、Extra
Contains additional information that is not suitable for display in other columns but is important
| key | desc |
|---|---|
| Using filesort | explain MySQL Will use an external index to sort the data , Instead of reading in the order of the indexes in the table |
| Using temporary | Temporary tables are used to save intermediate results ,MySQL Use temporary tables when sorting results , It is common in sorting order by And group queries group by |
| Using index | It means corresponding select The override index is used in the operation (Covering Index), Avoid accessing the data rows of the table , Good efficiency |
| Using where | Used where Conditions |
| Using join buffer | The change emphasizes that no index is used to get the connection conditions , And you need to connect buffers to store intermediate results . If this value appears , That should pay attention to , Depending on the specific situation of the query, you may need to add indexes to improve the performance . |
| impossible where | This value emphasizes where Statement will result in no eligible rows |
| distinct | once mysql Found a row that matches the row Union , No more searching |
| Select tables optimized away | SELECT The operation has been optimized so that it can no longer be optimized (MySQL Return data without traversing the table or index at all ) |
| No tables used | Query Use in statement from dual Or without any from Clause |
版权声明
本文为[Xiaodaoxian 97]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230315096392.html
边栏推荐
- “如何实现集中管理、灵活高效的CI/CD”在线研讨会精彩内容分享
- Eight elder brothers chronicle [4]
- Configure automatic implementation of curd projects
- The most easy to understand service container and scope of dependency injection
- Miniapi of. Net7 (special section): NET7 Preview3
- ASP. Net 6 middleware series - Custom middleware classes
- Blazor University (11) component - replace attributes of subcomponents
- MySql关键字GROUP_CONCAT,组合连接查询
- Flink实时数仓项目—DWS层设计与实现
- 编码电机PID调试(速度环|位置环|跟随)
猜你喜欢
![[Mysql] LEFT函數 | RIGHT函數](/img/26/82e0f2280de011636c26931a74e749.png)
[Mysql] LEFT函數 | RIGHT函數

C read / write binary file

MySQL port is occupied when building xampp
![[new version release] componentone added Net 6 and blazor platform control support](/img/08/71e7328f685a5cdd584f1bfdce5f2a.png)
[new version release] componentone added Net 6 and blazor platform control support

ASP. Net 6 middleware series - conditional Middleware

A comprehensive understanding of static code analysis

be based on. NETCORE development blog project starblog - (1) why do you need to write your own blog?

LoadRunner - performance testing tool
![Eight elder brothers chronicle [4]](/img/87/f695d0275f8a66b9def48a75668d15.png)
Eight elder brothers chronicle [4]

Xamarin effect Chapter 21 expandable floating operation button in GIS
随机推荐
Quartz. Www. 18fu Used in net core
Is it difficult to choose binary version control tools? After reading this article, you will find the answer
Utgard connection opcserver reported an error caused by: org jinterop. dcom. common. JIRuntimeException: Access is denied. [0x800
Mise en service PID du moteur de codage (anneau de vitesse | anneau de position | suivant)
Test experience data
Student achievement management
类似Jira的十大项目管理软件
yes. Net future
2022年P气瓶充装培训试题及模拟考试
. net core current limiting control - aspnetcoreratelimit
Huawei mobile ADB devices connection device is empty
12.<tag-链表和常考点综合>-lt.234-回文链表
First in the binary tree
可以接收多种数据类型参数——可变参数
[Mysql] LEFT函數 | RIGHT函數
数据库表中不建索引,在插入数据时,通过sql语句防止重复添加(转载)
Eight elder brothers chronicle [4]
Use split to solve the "most common words" problem
编码电机PID调试(速度环|位置环|跟随)
Mysql database design specification