explain the analysis of mysql

EXPLAIN //
the above mentioned id, SELECT_TYPE, the Table, of the type, possible_keys, Key, key_len, ref, rows, Extra
type of query, table name, connection type tables, indexes, queries used when possible, the actual use of the index, the index field length comparison, the column of the index, the number of scanning lines, the description of the implementation of the instructions
a, id
id id query flag if the same execution order is from top to bottom id value larger the higher the priority
two, type
type MySQL found manner desired rows in the table
type: ALL, index, range, ref , eq_ref, const, system, NULL ( from left to right, from poor to good performance)
ALL traverse the entire table to find a matching row
index index traverses only tree index
range only retrieves a row given range
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
eq_ref: REF Similarly, the difference in the index is a unique index using, 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

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

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.

Three, 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 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

 

四、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.

 

Five, 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

 

Six, 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

 

Seven, 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

 

Eight, Extra

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

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 mysql server retrieves line storage engine then filtered

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

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

Using join buffer: The use of the 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 can be improved.

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: Select tables optimized away

No tables used: Query statement from the use of or does not contain any clause from

Guess you like

Origin www.cnblogs.com/dphper/p/11300310.html