当前位置:网站首页>On the implementation plan of MySQL explain
On the implementation plan of MySQL explain
2022-07-04 14:53:00 【Tonghua misses the rain】
Catalog
Preface
We often use Explain
Check the execution plan , As we all know, this . But ask the interviewer during the interview , Do you use Explain
Mainly to see what ? The answer of the other party is mostly to check whether the index is used , This is obviously not the best answer
Explain
Each field and its meaning
id
: ExpressSQL
Identification of the order of execution ,SQL
From big to small executionselect_type
: Represents each... In the queryselect
The type of clausetable
: Show which table this row's data is about , Sometimes it's not a real nametype
: Expressmysql
How to find the desired row in the table , Also known as access type . Common types are :ALL, index, range, ref,eq_ref, const, system, NULL
( From left to right , Performance from poor to good )possible_keys
: Pointed out thatmysql
Which index can be used to find records in the table , If there is an index on the field involved in the query , Then the index will be listed , But not necessarily used by queriesKey
:key
Columns showmysql
Actually decide which key to use ( Indexes ), If index is not selected , The key isNULL
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 , namelykey_len
It is calculated according to the table definition , It is not retrieved from the table )ref
: Indicates the join matching condition of the above table , That is, which columns or constants are used to find values on index columnsrows
: Expressmysql
According to table statistics and index selection , Estimated number of rows to read to find the required record , In theory, the less , Better query performanceExtra
: This column containsmysql
Solve query details
stay Explain
In the execution plan , We focus on Type
and Extra
Two fields , They are the core
Explain
Medium Type
Explain
Medium Type
stay MySql
The official website of is interpreted as : Connection type (the join type
). It describes the scanning method used to find the required data . The most common scanning methods are
system
: Indicates that the data has been loaded into memory , No disk requiredIO
, This kind of scanning is the fastestconst
: Hit the primary key index or unique index , The connected part is a constant valueeq_ref
: Equivalent scanning of primary key index or non empty unique indexref
: Non primary key index or non unique index equivalent scanningrange
: Range scan , It's a range query on the index , It scans the index for values in a specific rangeindex
: Index tree scan , You need to scan all the data on the index treeALL
: Full table scan
The above scanning methods range from fast to slow :system > const > eq_ref > ref > range > index > ALL
Explain
Medium Extra
Explain
Medium Extra
The value is
Using index
: explainSQL
All column data to be returned is in an index tree , Without having to access the actual row recordUsing where
: explainSQL
Usedwhere
Condition filter data
explain select * from account_user_base where id > 4;
Using index condition
: Indicates that the index was indeed hit , But not all of the column data is on the index tree , You also need to access the actual row record
explain select * from account_user_security t1, account_user_base t2 where t1.user_id = t2.id;
Using filesort
: Explain to get the desired result set , All records need to be sorted . Typical , On a column that is not indexedorder by
, It will triggerfilesort
, The common optimizations are , stayorder by
Add index... To the column of , Avoid full ordering every time you query . For details, please refer to :mysql in order by PrincipleUsing temporary
: It indicates that a temporary table needs to be created to temporarily store intermediate results . This kind ofSQL
Statement performance is low , Often also need to optimize . Typicalgroup by
andorder by
At the same time , And when it works on different fields , It's going to create a temporary table , In order to calculate the final result set
边栏推荐
- Openresty current limiting
- No servers available for service: xxxx
- 深度学习7 Transformer系列实例分割Mask2Former
- Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
- PLC模拟量输入 模拟量转换FC S_ITR (CODESYS平台)
- Kubernets Pod 存在 Finalizers 一直处于 Terminating 状态
- First experience of ViewModel
- 10. (map data) offline terrain data processing (for cesium)
- SqlServer函数,存储过程的创建和使用
- Digi XBee 3 rf: 4 protocols, 3 packages, 10 major functions
猜你喜欢
IO流:节点流和处理流详细归纳。
leetcode:6109. Number of people who know the secret [definition of DP]
为什么国产手机用户换下一部手机时,都选择了iPhone?
【C语言】指针笔试题
LeetCode 1200 最小絕對差[排序] HERODING的LeetCode之路
Stm32f1 and stm32subeide programming example -max7219 drives 8-bit 7-segment nixie tube (based on GPIO)
[information retrieval] experiment of classification and clustering
Leetcode 1200 minimum absolute difference [sort] The Path of leetcode for heroding
如何配和弦
numpy笔记
随机推荐
03-存储系统
Five minutes of machine learning every day: why do we need to normalize the characteristics of numerical types?
LVGL 8.2 Line
[cloud native] how can I compete with this database?
[algorithm leetcode] interview question 04.03 Specific depth node linked list (Multilingual Implementation)
Ultrasonic distance meter based on 51 single chip microcomputer
Ranking list of databases in July: mongodb and Oracle scores fell the most
[information retrieval] experiment of classification and clustering
[C language] Pointer written test questions
自动控制原理快速入门+理解
Transplant tinyplay for imx6q development board QT system
openresty 限流
flink sql-client. SH tutorial
Openresty current limiting
Korean AI team plagiarizes shock academia! One tutor with 51 students, or plagiarism recidivist
如何配和弦
Data Lake (13): spark and iceberg integrate DDL operations
Gin integrated Alipay payment
LVGL 8.2 LED
Wt588f02b-8s (c006_03) single chip voice IC scheme enables smart doorbell design to reduce cost and increase efficiency