Explain the MySQL command interpreter

explain show how to use the index to handle mysql select statement and connection table. You can help choose a better index and write more optimized queries.

Use, plus explain before the select statement on it. Such as:

explain select * form account 

Similar to the following output

EXPLAIN column explanation:

the Table : This line of display data about which tables of

of the type : This is an important column that shows what type of connection used. From best to worst the connection type is const, eq_reg, ref, range, indexhe and ALL

possible_keys : displays the index in this table may apply. If empty, the index is not possible. May be selected from a suitable statement WHERE clause for the associated domain

Key : index actually used. If NULL, then do not use the index. In rare cases, MYSQL will choose less than the index optimization. In this case, you can be used in the SELECT statement USE INDEX (indexname) to force the use of an index or with IGNORE INDEX (indexname) to force the index ignored MYSQL

The key_len : length of the index used. Without loss of accuracy, a length as short as possible

REF : display column index which is used, if possible, is a constant

rows : MYSQL Based must check that the number of rows to return the requested data

Extra : MYSQL additional information about how to resolve the query. Will be discussed in Table 4.3, but here you can see the bad example of Using temporary and are Using filesort, meaning MYSQL can not use the index, the result is retrieved will be very slow

Interpretation Type column

Type: Tell us of access method used by the table, it contains the following main focus type.

all: full table scan.

const: Constant reading, at most, only one record matching, because it is constant, in fact, only need to read once.

eq_ref: it will only result there is a match, usually accessed via a primary key or unique key index.

fulltext: full-text index search.

index: full index scan.

index_merge: query using both (or more) index, and then combine the results of the index (Merge), and then reads the table data.

index_subquery: subquery returns result field is a combination index (or index combination), but not a primary key or a unique index.

rang: an index range scan.

ref: Join statement referenced index driven table queries.

ref_or_null: ref only difference is that in addition to using query index referenced by the query to add a null value.

system: The system table in which only one line of data;

unique_subquery: subquery returns the result field is a primary key or a unique combination of constraint.

Extra field interpretation

Extra: Additional details every step of the realization of the inquiry, the principal will be following.

Distinct: Find distinct value, when mysql found matching results first, the value of the query will stop, turn back the value of other queries.

Full scan on NULL key: an optimal way subquery, mainly in the face can not access the null value by using the index.

Range checked for each record (index map: N): MySQL by describing the manual, as MySQL Query Optimizer when the index is not found good can be used, if it is found in front of a table column value is known, the index portion may be used. For each combination of the front row of the table, MySQL or range may be used to check whether the access method to obtain index_merge line.

SELECT tables optimized away: when we use certain aggregate functions to access a field when there is an index, MySQL Query Optimizer will once positioned by the index directly to the desired data line to complete the inquiry. Of course, that can not have a GROUP BY operation in the Query. As used MIN () or MAX () time.

Using filesort: When Query contains ORDER BY operation, and can not use the index to complete the sort operations, MySQL Query Optimizer have to select the appropriate sorting algorithm.

Using index: all the required data can be obtained only in the Index, and then do not need to take the data in the table.

Using index for group-by: Using index and data access, as only the data required to read the index, when using Query or GROUP BY DISTINCT clause, also in the field if the packet index, the information would be in the Extra Using index for group-by.

Using temporary: When MySQL must use temporary tables in some operations, Using temporary information will appear in the Extra. The main common in the GROUP BY and ORDER BY and other operations.

Using where: If you do not read the table of all the data, or not just to get all the data required by the index, Using where the information appears.

Using where with pushed condition: It is a message just NDBCluster storage engine to appear, but also need to feature is available can be used by opening the Condition Pushdown Optimization. Control parameters engine_condition_pushdown.

Impossible WHERE noticed after reading const tables: MySQL Query Optimizer determines that the result can not exist by statistics collected.

No tables: Query statement using FROM DUAL or does not contain any FROM clause.

Not exists: In certain optimization left connection, MySQL Query Optimizer by changing the composition of the original Query used may be partially reduce data access times.

Guess you like

Origin www.cnblogs.com/cxhfuujust/p/11100855.html