当前位置:网站首页>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
边栏推荐
- Implementation of macro instruction of first-order RC low-pass filter in signal processing (easy touch screen)
- Five minutes per day machine learning: use gradient descent to complete the fitting of multi feature linear regression model
- Openresty current limiting
- LVGL 8.2 Line
- Wt588f02b-8s (c006_03) single chip voice IC scheme enables smart doorbell design to reduce cost and increase efficiency
- Pandora IOT development board learning (RT thread) - Experiment 3 button experiment (learning notes)
- C language course design questions
- How to handle exceptions in multithreading?
- LVGL 8.2 LED
- Programmer turns direction
猜你喜欢
Luo Gu - some interesting questions
Leetcode 1200 minimum absolute difference [sort] the way of leetcode in heroding
Pandora IOT development board learning (RT thread) - Experiment 3 button experiment (learning notes)
阿里被裁员工,找工作第N天,猎头又传来噩耗...
Test evaluation of software testing
5g TV cannot become a competitive advantage, and video resources become the last weapon of China's Radio and television
Summary of common problems in development
LVGL 8.2 LED
(1)性能调优的标准和做好调优的正确姿势-有性能问题,上HeapDump性能社区!
LVGL 8.2 Draw label with gradient color
随机推荐
Classify boost libraries by function
5G电视难成竞争优势,视频资源成中国广电最后武器
Practical puzzle solving | how to extract irregular ROI regions in opencv
阿里被裁员工,找工作第N天,猎头又传来噩耗...
remount of the / superblock failed: Permission denied
Leetcode 1200 minimum absolute difference [sort] The Path of leetcode for heroding
An overview of 2D human posture estimation
微博、虎牙挺进兴趣社区:同行不同路
Gin integrated Alipay payment
Halo effect - who says that those with light on their heads are heroes
LVLG 8.2 circular scrolling animation of a label
函数计算异步任务能力介绍 - 任务触发去重
Count the running time of PHP program and set the maximum running time of PHP
韩国AI团队抄袭震动学界!1个导师带51个学生,还是抄袭惯犯
Summary of common problems in development
LVGL 8.2 Sorting a List using up and down buttons
numpy笔记
C language set operation
Digi XBee 3 RF: 4个协议,3种封装,10个大功能
Free, easy-to-use, powerful lightweight note taking software evaluation: drafts, apple memo, flomo, keep, flowus, agenda, sidenote, workflow