Mysql Explain Plan of Implementation (optimization strategy)

Mysql Explain 

Explain the information out there is 10, namely:

id、select_type、table、type、possible_keys、key、key_len、ref、rows、Extra

Summary Description:
the above mentioned id: select identifier
select_type: indicates the type of query.
table: Table output result set
partitions: matching partition
type: represents the type of connection tables
possible_keys: when querying, the index may be used
key: indicates the index actually used
key_len: length of the index field
ref: Comparison column of index
rows : the number of lines scanned (the estimated number of rows)
filtered: filtered percentage table line conditions
Extra: implementation described and illustrated

 

A, id     

SELECT identifier. This is a SELECT query sequence number

My understanding is that the order of execution of SQL identifier, execute SQL descending

1. id are the same, the order from top to bottom

2. If the subquery, id serial number is incremented, id value the greater the higher the priority, the first to be executed

3. If the same id, may be considered as a group, from the order of execution down; in all groups, the greater the id value, the higher priority, the first execution

Two, select_type each type of query select clause

1: SIMPLE (simple SELECT, not using UNION or subqueries)

2: PRIMARY (subquery outermost query, if the query contains any complex sub-portion, the outermost layer is marked as a PRIMARY select)

3: UNION (UNION second or later SELECT statement)

4: DEPENDENT UNION (UNION second or later SELECT statement, depending on the outside of the query)

5: UNION RESULT (second start later select the UNION result, union all select statement)

6: SUBQUERY (first subquery SELECT, the results do not rely on external queries)

7: DEPENDENT SUBQUERY (first subquery SELECT, rely on external queries)

8: DERIVED (derived table SELECT, FROM clause subqueries)

9: UNCACHEABLE SUBQUERY (the result of a sub-query can not be cached, it must re-evaluate the first row are linked)

Three, table

This step of the display to access the database table name (display data on this line is what tables are), sometimes not real table name, may be referred to as, for example, the above e, d, it may be the result of the implementation of the first steps for short

Four, type

Table access method, MySQL find a way to express the desired line in the table, also known as "access type."

Common types: ALL, index, range, ref, eq_ref, const, system, NULL; left to right, from poor to good performance

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

2: index: Full Index Scan, index and index types to distinguish ALL traversing the index tree only

3: range: retrieve only to the line given range, using an index to select the rows

4: ref: indicates the matching condition of the connection table, that is, which is used to find the column or constant value in the index column

5: 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

5: 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 can convert the query to a constant, const type of system is a special case, in the case where only one row of table queries, the use of system

6: NULL: MySQL decomposition statement in the optimization process, even without access to a table or index when performing, for example, selected from an indexed column in the minimum can be done through a separate index lookup. 

五、possible_keys

It 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 an index (the query can be utilized, if there is no index display null )

This column is completely independent of the order table shown EXPLAIN output. This means that some key possible_keys in fact can not be generated by using the order table.
If the column is NULL, no relevant index. In this case, you can see by examining the WHERE clause if it refers to some column or columns for the index to improve the performance of your query. If so, create an appropriate index and check the query again with EXPLAIN

Six, Key

MySQL key column shows the actual decision to use a key (index) must contain in the possible_keys

If you do not select an index, the key is NULL. To force MySQL to use or ignore possible_keys column index, use FORCE INDEX in the query, USE INDEX or IGNORE INDEX.

七, key_len

Indicates 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., is calculated on the basis key_len table definition, not retrieved by the table)

Without loss of accuracy, a length as short as possible 

Eight, ref

Comparison with the column index, indicates the connection of the matching condition in the above Table, i.e. which columns or constants are used to find the value in the index column

Nine, rows

 Estimate the number of rows in the result set, according to denote MySQL table statistics and index selection, the estimated number of lines needed to find records to be read

 

 

Ten, Extra

This column contains detailed information to solve the MySQL query, the following situations:

1: Using where: do not read all the information in the table, only the index can get the data, which occurs at the time of the request for a list of all the parts are the same index, expressed in mysql server storage engine retrieve a row and then filtered

2: Using temporary: MySQL expressed the need to use temporary tables to store the result set, common in the sorting and grouping queries, common group by; order by

3: Using filesort: When Query contains order by operation, and can not use the index to complete the sort operation called "Sort files"

4: Using join buffer: used to change the value of the index 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 can be improved.

5: Impossible where: This value is highlighted where a statement would cause no qualifying rows (by collecting statistics exist result impossible).

Aggregate function may only result in the return line by using only the index value means the optimizer: 6: Select tables optimized away

7: No tables used: Query statement from dual use or free from any of clauses

 

 

to sum up:

· EXPLAIN will not tell you to customize the query function affects the situation on triggers, stored procedures or user information

· EXPLAIN not consider Cache

· EXPLAIN does not show MySQL optimization work done in the execution of the query

• Partial 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 50 original articles · won praise 2 · Views 2326

Guess you like

Origin blog.csdn.net/eafun_888/article/details/96565557