Detailed mysql explain bis

This switched: https://www.cnblogs.com/gomysql/p/3720123.html

At work, we used to capture the performance of the most common problems slow query is open, poor positioning of the efficiency of SQL, so when we locate a SQL also not get away, we also need to know the SQL execution plan, such as a full table scan or index scan, which need to be accomplished by EXPLAIN. EXPLAIN command to see how the optimizer to determine the main method for executing the query. MySQL can help us understand the cost-based optimizer, you can also get a lot of details that may be taken into account optimizer access policy, and when running SQL statements which strategy is expected to be adopted optimizer. Note that generated QEP is uncertain, it may change based on many factors. MySQL will not be a QEP and a given query binding, QEP by each SQL statement executed to determine the actual situation, even if the use of stored procedures as well. Although SQL statements in stored procedures are pre-parsed, but still was only QEP determine each time call a stored procedure.

What can be known through the implementation plan?

Copy the code

(root@yayun-mysql-server) [test]>explain select d1.age, t2.id from (select age,name from t1 where id in (1,2))d1, t2 where d1.age=t2.age group by d1.age, t2.id order by t2.id;
+----+-------------+------------+-------+---------------+---------+---------+--------+------+---------------------------------+
| id | select_type | table      | type  | possible_keys | key     | key_len | ref    | rows | Extra                           |
+----+-------------+------------+-------+---------------+---------+---------+--------+------+---------------------------------+
|  1 | PRIMARY     | <derived2> | ALL   | NULL          | NULL    | NULL    | NULL   |    2 | Using temporary; Using filesort |
|  1 | PRIMARY     | t2         | ref   | age           | age     | 5       | d1.age |    1 | Using where; Using index        |
|  2 | DERIVED     | t1         | range | PRIMARY       | PRIMARY | 4       | NULL   |    2 | Using where                     |
+----+-------------+------------+-------+---------------+---------+---------+--------+------+---------------------------------+
3 rows in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

MySQL implementation plan is called
1.EXPLAIN SELECT ......
variants:
2.EXPLAIN EXTENDED SELECT ......
execution plan "decompile" into the SELECT statement, run SHOW WARNINGS 
available optimized MySQL query optimizer after
3.EXPLAIN PARTITIONS the SELECT ......
information generated EXPLAIN partition table for QEP

Information contained in the Plan of Implementation

+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref  | rows | Extra       |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+

1. id:

It contains a set of numbers indicating the order of clauses or select a query execution operation table

Example ( the same id, execution order from top to bottom )

Copy the code

(root@yayun-mysql-server) [test]>explain select t2.* from t1, t2, t3 where t1.id=t2.id and t1.id=t3.id and t1.name='';
+----+-------------+-------+--------+---------------+---------+---------+------------+------+--------------------------+
| id | select_type | table | type   | possible_keys | key     | key_len | ref        | rows | Extra                    |
+----+-------------+-------+--------+---------------+---------+---------+------------+------+--------------------------+
|  1 | SIMPLE      | t1    | ref    | PRIMARY,name  | name    | 63      | const      |    1 | Using where; Using index |
|  1 | SIMPLE      | t2    | eq_ref | PRIMARY       | PRIMARY | 4       | test.t1.id |    1 |                          |
|  1 | SIMPLE      | t3    | eq_ref | PRIMARY       | PRIMARY | 4       | test.t1.id |    1 | Using index              |
+----+-------------+-------+--------+---------------+---------+---------+------------+------+--------------------------+
3 rows in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

Example (if a subquery, id serial number is incremented, id value the greater the higher the priority, the first to be executed)

Copy the code

(root@yayun-mysql-server) [test]>explain select t2.* from t2 where id = (select id from t1 where id = (select t3.id from t3 where t3.name=''));
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra                                               |
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+
|  1 | PRIMARY     | NULL  | NULL | NULL          | NULL | NULL    | NULL | NULL | Impossible WHERE noticed after reading const tables |
|  2 | SUBQUERY    | NULL  | NULL | NULL          | NULL | NULL    | NULL | NULL | no matching row in const table                      |
|  3 | SUBQUERY    | t3    | ref  | name          | name | 63      |      |    1 | Using where; Using index                            |
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+
3 rows in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

Example (if the same id, may be considered as a group, from the order of execution down;, id value is larger in all groups, the higher the priority, the first)

Copy the code

(root@yayun-mysql-server) [test]>explain select t2.* from (select t3.id from t3 where t3.name='')s1, t2 where s1.id=t2.id;
+----+-------------+------------+--------+---------------+---------+---------+-------+------+--------------------------+
| id | select_type | table      | type   | possible_keys | key     | key_len | ref   | rows | Extra                    |
+----+-------------+------------+--------+---------------+---------+---------+-------+------+--------------------------+
|  1 | PRIMARY     | <derived2> | system | NULL          | NULL    | NULL    | NULL  |    1 |                          |
|  1 | PRIMARY     | t2         | const  | PRIMARY       | PRIMARY | 4       | const |    1 |                          |
|  2 | DERIVED     | t3         | ref    | name          | name    | 63      |       |    1 | Using where; Using index |
+----+-------------+------------+--------+---------------+---------+---------+-------+------+--------------------------+
3 rows in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

2. select_type

Each type shown query select clause (OR simple complex)

a SIMPLE:. query or subquery does not contain the UNION
B if the query contains any complex sub-portion, the outermost query were labeled as:. a PRIMARY
. C contains the subquery SELECT list or WHERE, the subquery is marked: SUBQUERY
D contained in the sub-query fROM list is marked:. dERIVED (derivative) is used to indicate the sub-select from clause is included in a query, mysql recursively executed and the result in a temporary table in. Internal server is called "derived form", because the temporary table is derived from the subquery
e If after the second SELECT appears UNION, were labeled UNION;. UNION if included in the FROM clause of a subquery , will be marked as the outer SELECT: DERIVED
F results acquired from the SELECT list is marked UNION:. UNION rESULT

UNION SUBQUERY and may also be labeled and DEPENDENT UNCACHEABLE.
DEPENDENT means select dependent data found in the outer query.
Select certain characteristics UNCACHEABLE means to prevent the results are cached in a item_cache in.

Example

Copy the code

(root@yayun-mysql-server) [test]>explain select d1.name, ( select id from t3) d2 from (select id,name from t1 where name='')d1 union (select name,id from t2);
+----+--------------+------------+--------+---------------+------+---------+------+------+--------------------------+
| id | select_type  | table      | type   | possible_keys | key  | key_len | ref  | rows | Extra                    |
+----+--------------+------------+--------+---------------+------+---------+------+------+--------------------------+
|  1 | PRIMARY      | <derived3> | system | NULL          | NULL | NULL    | NULL |    0 | const row not found      |
|  3 | DERIVED      | t1         | ref    | name          | name | 63      |      |    1 | Using where; Using index |
|  2 | SUBQUERY     | t3         | index  | NULL          | age  | 5       | NULL |    6 | Using index              |
|  4 | UNION        | t2         | index  | NULL          | name | 63      | NULL |    4 | Using index              |
| NULL | UNION RESULT | <union1,4> | ALL    | NULL          | NULL | NULL    | NULL | NULL |                          |
+----+--------------+------------+--------+---------------+------+---------+------+------+--------------------------+
5 rows in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

The first line: id column is 1, represents a select, primary select_type column indicates that the query outer query, table column is labeled <derived3>, represents a query result is derived from the table, which represents the derived query since the third select query, that is, the id of select 3.
Second row: id 3, showing the order of execution of the query 2 (4 => 3), is part of the query, select the third. Because the query contains in from, so is derived.
Third row: select list of the subquery, select_type as a subquery, the query for the entire second select.
Fourth row: select_type for the union, explained fourth select a union in the second select, the first execution.
Fifth row: the union representatives from the temporary table rows are read phase, table column <union1,4> representation of the results of using a union operation and the fourth select.

3. type                                       

MySQL find a way to express the desired line in the table, also known as "access type", common types are as follows:

 ALL, index,  range, ref, eq_ref, const, system, NULL

From left to right, from worst to best performance

Example

a ALL:. Full Table Scan, MySQL will traverse the whole table to find matching rows

Copy the code

(root@yayun-mysql-server) [test]>explain select * from t1 where email='';
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra       |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
|  1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL |    4 | Using where |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

b index:. Full Index Scan, index differs only ALL is traversing the index tree index type

Copy the code

(root@yayun-mysql-server) [test]>explain select id from t1;
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type  | possible_keys | key  | key_len | ref  | rows | Extra       |
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
|  1 | SIMPLE      | t1    | index | NULL          | age  | 5       | NULL |    4 | Using index |
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

. C range: scan range index, the index scan begins at a certain point, the line returns a match value range. Index range scan is apparent with a where clause with or between <,> query. When mysql using the index to find a sequence of values, for example, the IN () and OR list is also displayed range (scanning range), of course, the performance of the above is different.

Copy the code

(root@yayun-mysql-server) [test]>explain select * from t1 where id in (1,4);
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref  | rows | Extra       |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
|  1 | SIMPLE      | t1    | range | PRIMARY       | PRIMARY | 4       | NULL |    2 | Using where |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
1 row in set (0.00 sec)

(root@yayun-mysql-server) [test]>explain select * from t1 where id between 1 and 4;
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref  | rows | Extra       |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
|  1 | SIMPLE      | t1    | range | PRIMARY       | PRIMARY | 4       | NULL |    3 | Using where |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
1 row in set (0.00 sec)

(root@yayun-mysql-server) [test]>explain select * from t1 where id=1 or id=4;       
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref  | rows | Extra       |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
|  1 | SIMPLE      | t1    | range | PRIMARY       | PRIMARY | 4       | NULL |    2 | Using where |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
1 row in set (0.01 sec)

(root@yayun-mysql-server) [test]>explain select * from t1 where id > 1;      
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref  | rows | Extra       |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
|  1 | SIMPLE      | t1    | range | PRIMARY       | PRIMARY | 4       | NULL |    3 | Using where |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
1 row in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

d ref:. prefix non-unique index scans or scan a unique index, a return matching rows separate value

Copy the code

(root@yayun-mysql-server) [test]>explain select * from t1 where name='yayun';
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref   | rows | Extra       |
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
|  1 | SIMPLE      | t1    | ref  | name          | name | 63      | const |    1 | Using where |
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
1 row in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

e eq_ref:. REF Similarly, the difference in the index using a unique index for each index key, only one record in the table match, simply put, is to use a multi-table join as a primary key or a unique key associated with conditions

Copy the code

(root@yayun-mysql-server) [test]>explain select t1.name from t1, t2 where t1.id=t2.id;
+----+-------------+-------+--------+---------------+---------+---------+------------+------+-------------+
| id | select_type | table | type   | possible_keys | key     | key_len | ref        | rows | Extra       |
+----+-------------+-------+--------+---------------+---------+---------+------------+------+-------------+
|  1 | SIMPLE      | t1    | index  | PRIMARY       | name    | 63      | NULL       |    4 | Using index |
|  1 | SIMPLE      | t2    | eq_ref | PRIMARY       | PRIMARY | 4       | test.t1.id |    1 | Using index |
+----+-------------+-------+--------+---------------+---------+---------+------------+------+-------------+
2 rows in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

f const, system:. When a part of MySQL query optimization, and converted to a constant, using these types of access. As will be placed where the primary key list, MySQL the query can be converted to a constant

Copy the code

(root@yayun-mysql-server) [test]>explain select * from ( select * from t1 where id=1)b1;
+----+-------------+------------+--------+---------------+---------+---------+------+------+-------+
| id | select_type | table      | type   | possible_keys | key     | key_len | ref  | rows | Extra |
+----+-------------+------------+--------+---------------+---------+---------+------+------+-------+
|  1 | PRIMARY     | <derived2> | system | NULL          | NULL    | NULL    | NULL |    1 |       |
|  2 | DERIVED     | t1         | const  | PRIMARY       | PRIMARY | 4       |      |    1 |       |
+----+-------------+------------+--------+---------------+---------+---------+------+------+-------+
2 rows in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

Note: system const type is a special case, in the case of only one row of table query, use the system

g NULL:. MySQL decomposition statement optimization process, even without access to a table or index is performed, for example, from a selected minimum value in the index column can be accomplished by a single index lookup.

Copy the code

(root@yayun-mysql-server) [test]>explain select * from t1 where id = (select min(id) from t2);
+----+-------------+-------+-------+---------------+---------+---------+-------+------+------------------------------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref   | rows | Extra                        |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+------------------------------+
|  1 | PRIMARY     | t1    | const | PRIMARY       | PRIMARY | 4       | const |    1 |                              |
|  2 | SUBQUERY    | NULL  | NULL  | NULL          | NULL    | NULL    | NULL  | NULL | Select tables optimized away |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+------------------------------+
2 rows in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

4. possible_keys
indicates which indexes MySQL could use to find records in a table, query if there is an index, the index will be listed on the fields involved, but not necessarily be queried using


5. key
to display the index MySQL actually used in the query, if not use the index, shown as NULL

Example

Copy the code

(root@yayun-mysql-server) [test]>explain select id,age from t1;
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type  | possible_keys | key  | key_len | ref  | rows | Extra       |
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
|  1 | SIMPLE      | t1    | index | NULL          | age  | 5       | NULL |    4 | Using index |
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

Key_len 6. The
number of bytes used in the index, the index can be used in the query is calculated by the column length (the maximum possible length values of the index fields displayed key_len, not actual length, i.e. key_len calculation is defined according to Table have not retrieved by the table)

7. ref
connecting the matching conditions are shown in Table, i.e. constant, or column which is used to find the value of the index column

8. rows
represent MySQL table based on statistics and index selection, the estimate of the required records needed to find
the number of lines to be read

Example

Copy the code

(root@yayun-mysql-server) [test]>explain select * from t1 , t2 where t1.id=t2.id and t2.name='atlas';
+----+-------------+-------+--------+---------------+---------+---------+------------+------+-------------+
| id | select_type | table | type   | possible_keys | key     | key_len | ref        | rows | Extra       |
+----+-------------+-------+--------+---------------+---------+---------+------------+------+-------------+
|  1 | SIMPLE      | t2    | ref    | PRIMARY,name  | name    | 63      | const      |    1 | Using where |
|  1 | SIMPLE      | t1    | eq_ref | PRIMARY       | PRIMARY | 4       | test.t2.id |    1 |             |
+----+-------------+-------+--------+---------------+---------+---------+------------+------+-------------+
2 rows in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

9. Extra
unsuitable for display but important additional information in the other column
a. Using index
This value indicates that the corresponding select operation using a covering index (Covering Index)

Example

Copy the code

(root@yayun-mysql-server) [test]>explain select id from t1;
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type  | possible_keys | key  | key_len | ref  | rows | Extra       |
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
|  1 | SIMPLE      | t1    | index | NULL          | age  | 5       | NULL |    4 | Using index |
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

Covering index (Covering Index)
MySQL can use an index to return the select list of fields, without having to read the data file again according to the index
contains all the data needed to satisfy the query index is called a covering index (Covering Index)
Note: If you use a covering index must pay attention to remove only the select list columns need not select *, because if you do together all index fields will cause the index file is too large, the query performance degradation

b. Using where
represents mysql server will be filtered before storage engine to retrieve rows. Many involved in the condition where the index column, when (and if) when it reads the index can be stored engine test, and therefore not all queries will be displayed with where the words "Using where". Sometimes "Using where" is a hint: the query may benefit from different index.

Example

Copy the code

(root@yayun-mysql-server) [test]>explain select id,name from t1 where id<4;
+----+-------------+-------+-------+---------------+------+---------+------+------+--------------------------+
| id | select_type | table | type  | possible_keys | key  | key_len | ref  | rows | Extra                    |
+----+-------------+-------+-------+---------------+------+---------+------+------+--------------------------+
|  1 | SIMPLE      | t1    | index | PRIMARY       | name | 63      | NULL |    4 | Using where; Using index |
+----+-------------+-------+-------+---------------+------+---------+------+------+--------------------------+
1 row in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

c. Using temporary
expressed MySQL need to use a temporary table to store the result set, common in the sorting and grouping queries

This value indicates an internal temporary (memory-based) table. A query might use multiple temporary tables. There are many reasons can cause MySQL to create temporary tables during query execution. Two common reasons is the use of DISTINCT in from different tables, or use a different ORDER BY and GROUP BY columns. You can enforce a temporary table using a disk-based MyISAM storage engine. The main reason for this is two-fold:
1) internal temporary table exceeds the limit the space occupied by the system variables min (the tmp_table_size, max_heap_table_size)
2) using the TEXT / BLOB column

Example

Copy the code

(root@yayun-mysql-server) [test]>explain select id from t1 where id in (1,2) group by age,name;
+----+-------------+-------+-------+---------------+---------+---------+------+------+----------------------------------------------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref  | rows | Extra                                        |
+----+-------------+-------+-------+---------------+---------+---------+------+------+----------------------------------------------+
|  1 | SIMPLE      | t1    | range | PRIMARY       | PRIMARY | 4       | NULL |    2 | Using where; Using temporary; Using filesort |
+----+-------------+-------+-------+---------------+---------+---------+------+------+----------------------------------------------+
1 row in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

d. filesort the Using
MySQL can not use indexes to complete the sorting operation is called "Sort files"

Example

Copy the code

(root@yayun-mysql-server) [test]>explain select id,age from t1 order by name; 
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra          |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
|  1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL |    4 | Using filesort |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
1 row in set (0.00 sec)

(root@yayun-mysql-server) [test]>explain select id,age from t1 order by age; 
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type  | possible_keys | key  | key_len | ref  | rows | Extra       |
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
|  1 | SIMPLE      | t1    | index | NULL          | age  | 5       | NULL |    4 | Using index |
+----+-------------+-------+-------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

e. Using join buffer
changed using an index value is not stressed while obtaining a connection condition, and the need to connect a buffer to store intermediate results. If this value is present, it should be noted, you may need to add an index based on the specific circumstances of the query to improve performance.

Example

Copy the code

(root@yayun-mysql-server) [test]>explain select t1.name from t1 inner join t2 on t1.name=t2.name;
+----+-------------+-------+-------+---------------+------+---------+--------------+------+--------------------------+
| id | select_type | table | type  | possible_keys | key  | key_len | ref          | rows | Extra                    |
+----+-------------+-------+-------+---------------+------+---------+--------------+------+--------------------------+
|  1 | SIMPLE      | t1    | index | name          | name | 63      | NULL         |    4 | Using index              |
|  1 | SIMPLE      | t2    | ref   | name          | name | 63      | test.t1.name |    2 | Using where; Using index |
+----+-------------+-------+-------+---------------+------+---------+--------------+------+--------------------------+
2 rows in set (0.00 sec)

(root@yayun-mysql-server) [test]>alter table t1 drop key name;                                   
Query OK, 0 rows affected (0.02 sec)
Records: 0  Duplicates: 0  Warnings: 0

(root@yayun-mysql-server) [test]>alter table t2 drop key name; 
Query OK, 0 rows affected (0.02 sec)
Records: 0  Duplicates: 0  Warnings: 0

(root@yayun-mysql-server) [test]>explain select t1.name from t1 inner join t2 on t1.name=t2.name;
+----+-------------+-------+------+---------------+------+---------+------+------+--------------------------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra                          |
+----+-------------+-------+------+---------------+------+---------+------+------+--------------------------------+
|  1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL |    4 |                                |
|  1 | SIMPLE      | t2    | ALL  | NULL          | NULL | NULL    | NULL |    4 | Using where; Using join buffer |
+----+-------------+-------+------+---------------+------+---------+------+------+--------------------------------+
2 rows in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

f. Impossible where
这个值强调了where语句会导致没有符合条件的行。

Example

Copy the code

(root@yayun-mysql-server) [test]>EXPLAIN SELECT * FROM t1 WHERE 1=2;
+----+-------------+-------+------+---------------+------+---------+------+------+------------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra            |
+----+-------------+-------+------+---------------+------+---------+------+------+------------------+
|  1 | SIMPLE      | NULL  | NULL | NULL          | NULL | NULL    | NULL | NULL | Impossible WHERE |
+----+-------------+-------+------+---------------+------+---------+------+------+------------------+
1 row in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

h. Select tables optimized away
这个值意味着仅通过使用索引,优化器可能仅从聚合函数结果中返回一行.

Example

Copy the code

(root@yayun-mysql-server) [test]>explain select max(id) from t1;
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra                        |
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
|  1 | SIMPLE      | NULL  | NULL | NULL          | NULL | NULL    | NULL | NULL | Select tables optimized away |
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
1 row in set (0.00 sec)

(root@yayun-mysql-server) [test]>

Copy the code

I. Index merges
when MySQL decides to use more than one index, when given in a table, one of the following formats will appear, and a detailed index of the combined use of the type description.
Sort_union the Using (...)
the Using of Union (...)
the Using INTERSECT (...)

 

Summary:
• EXPLAIN will not tell you about triggers, stored procedures or user-defined functions from prejudice to a query
• EXPLAIN not consider Cache
• EXPLAIN does not show MySQL optimization work done in the execution of the query
• Some statistics are estimates, not exact values
• EXPALIN can only be explained SELECT operations, other operations to be rewritten as a SELECT after viewing the execution plan.

Published 171 original articles · won praise 46 · views 190 000 +

Guess you like

Origin blog.csdn.net/LHDZ_BJ/article/details/89533762