当前位置:网站首页>Explain usage and result analysis
Explain usage and result analysis
2022-07-16 06:07:00 【Kuo-Teng】
explain Application method and result analysis
1. What is? explain command
explain The command is to view MySQL The main methods of how the query optimizer executes queries , Can well analyze SQL Statement execution .
Whenever encountered slow execution SQL, You can use explain Order to check SQL Implementation of , And analyze according to the operation results , Adopt corresponding methods to SQL Statement optimization .
adopt explain We can get the following information :
- Read order of tables
- Operation type of data read operation
- Which indexes can be used
- Which indexes are actually used
- References between tables
- How many rows per table are queried by the optimizer
2. How to use explain command
Just in SQL Use... Before the statement explain Key words can be used ;
Such as :
EXPLAIN SELECT * FROM student_info WHERE student_id = 'A01234567';
3. analysis explain Command execution result
In execution explain After the command , You will get an output with many columns , Let's take a look at the meaning of each column .
3.1. id
- If more lines
ididentical , The order of execution is from top to bottom ; - If it's a subquery ,
idThe serial number of will increase ,idThe higher the value, the higher the priority , The first to be executed ; - If more lines
idSome are the same and some are different , thatidThe same can be thought of as a group , Execute from top to bottom in the same group ;id Large groups are preferred ;
3.2. select_type
select_type What's shown is SELECT The type of :
SIMPLE: ordinarySELECT, Not usedUNIONOr subquery ;PRIMARY: Outermost layerSELECT;UNION: The second floor , staySELECTThen I usedUNION;DEPENDENT UNION:UNIONThe second in the statementSELECT, Rely on external subqueries ;UNION RESULT:UNIONResult ;SUBQUERY: First in subquerySELECT;DEPENDENT SUBQUERY: First in subquerySELECT, Depends on external queries ;DERIVED: Export table'sSELECT(FROMA subquery of a clause );
3.3. table
Displays which table the corresponding row is accessing , Usually the table name or the alias of the table ( If SQL It defines the alias );
3.4. type
type What is shown is what type of query is used , all type The order from good to bad is as follows :system > const > eq_ref > ref > range > index > all;
system: There is only one line in the table ( It's equal to the system table ), This is aconstType of specials , Not usually , This can also be ignored ;const: Indicates that it is found through index once ,constbe used forprimary keyperhapsuniqueIndexes . Because only one line of data is matched , So soon . For example, place the primary key inwhereIn the sentence ,MySQLYou can convert the query to a constant ;eq_ref: Unique index scan , For each index key , Only one record in the table matches it . Common in primary key or unique index scan ;ref: Non unique index scan , Returns all rows that match a single value , In essence, it is also an index access , It returns all rows that match a single value , However , It may find more than one eligible row , So it should be a mixture of search and scan ;range: Retrieve only rows in the given range , Use an index to select rows ,keyColumn shows which index is used , It's usually in yourwhereStatementbetween,<,>,inAnd so on , This range scan index is better than full table scan , Because it just needs to start at a certain point in the index , And end at another point , Don't scan all indexes ;index: Full table scan ,indexAndallThe difference forindexType only traverses the index tree . This is usually better thanallfast , Because index files are usually smaller than data files .( That is to say, althoughallandindexRead the whole watch , butindexIt's read from the index , andallIt's read from the hard disk ) ;all: Full table scan , Will traverse the entire table to find the matching rows ;
3.5. possible_keys
This column shows which indexes the query can use , This is based on the columns accessed by the query and the comparison operators used .
If there is an index on the field involved in the query , Then the index will be listed , But it doesn't have to be actually used by the query .
3.6. key
Show MySQL Decide which index to use to optimize access to the table . If NULL, No index is used .( Possible causes include not indexing or index failure )
If the index does not appear in possible_keys In the column , that MySQL It was chosen for other reasons, such as choosing an overlay index , Even if not where Clause .
In other words ,possible_keys It reveals which index is helpful for efficient row lookup , and key It shows which index the optimization adopts can minimize the query cost .
3.7. key_len
Shows MySQL The number of bytes used in the index , You can use this column to calculate the length of the index used in the query . Without losing accuracy , The shorter the length, the better .
3.8. ref
Show which field or constant is related to key Used together .
3.9. rows
Express MySQL Estimated number of rows to read in order to find the required row . According to the statistical information of the table and the selection of the index , This estimate may be very inaccurate . By putting all rows Multiply column values by , You can roughly estimate the number of rows that the entire query will check . The smaller the better. .
3.10. filtered
This column is MySQL 5.1 Newly added in , It shows that the table meets a certain condition (where Clause or join condition ) The percentage of a pessimistic estimate made by the number of records .
3.11. Extra
This column contains additional information that is not suitable for display in other columns . Common and most important values are :
Using indexExpressMySQLWill use overlay index , To avoid back table queries . Don't index overlay andindexAccess types are confused ;Using whereExpressMySQLThe server will filter the rows after the storage engine retrieves them ;Using temporaryExpressMySQLA temporary table is used when sorting query results ;Using filesortExpressMySQLAn external index will be used to sort the results , Instead of reading rows from the table in index order .MySQLThere are two file sorting algorithms , Both can be done in memory or on disk . butexplainI won't tell youMySQLWhat kind of , It won't tell you whether the sorting is done in memory or on disk ;Range checked for each record(index map:N)Indicates that there is no useful index , The new index will be reevaluated on each row of the join .NIs shown inpossible_keysBitmap of index in column , And it's redundant ;Using unionExpressMySQLThe index merging strategy is used , Index merging strategy is sometimes the result of optimization , But in fact, it often shows that the indexes on the table are badly built .
边栏推荐
- Intranet penetration notes - Three Layer Discovery and four layer discovery
- Experimental report on using spark to predict repeat customers
- Automatic deployment of server docking code cloud webhooks -- ultra detailed -- PHP
- unity实验-模拟太阳系星体运动
- 开源实习 | Compiler SIG 实习任务正式发布,欢迎报名申请!
- explain使用方法及结果分析
- It's 5 days late to convert the string to time. Pit avoidance Guide
- Expanding knowledge -- hijacking technology of JS
- Built in function of JS array
- Nftscan Developer Platform launches Multi Chain NFT data pro API service
猜你喜欢

蚂蚁集团开源大规模视频侵权定位数据集

sniffer Pro對ARP協議的分析、捕獲與模擬攻擊
Experimental report on using spark to predict repeat customers

谷歌浏览器无法打开localhost:3000,打开localhost就跳转测试地址问题

Some small problems encountered in using Baidu lightweight server LS

Analysis, capture and simulation attack of Sniffer Pro on ARP Protocol

MSF利用永恒之蓝渗透win2003

Intranet penetration notes - Three Layer Discovery and four layer discovery

MSF infiltrates Win2003 with eternal blue

Compilation principle - parser design
随机推荐
Some small problems encountered in using Baidu lightweight server LS
微信小程序开发二三事
MySQL-多表查询-联合查询/子查询
_button.enable=NO不起作用
Wechat payment refund PHP
SNMP started
NFT 交易市场主要使用 ETH 本位进行交易的局面是如何形成的?
开源实习 | Compiler SIG 实习任务正式发布,欢迎报名申请!
【MIT Missing Semester L3】熟练掌握Vim操作
38.js-- prototype exercise cases (face-to-face examination questions for proofreading)
自定义Loading动画
antd setFieldsValue警告问题 Cannot use `setFieldsValue` until you use `getFieldDecorator` or
YUV转UIImage
Intranet penetration notes - Sticky Keys and system command information collection
阿里云 centOS7 安装和远程链接mysql
Infrastructure nftscan officially released Solana network NFT browser
Unity experiment - control the movement of game objects
PHP docking wechat payment native TP5 framework
ES6 -- symbol() and map()
ES6 -- Deconstruction assignment (key)