mysql Explain low version

Explain: mysql execution plan performance analysis

grammar:

  explain+sql

Field explanation:
id:

  Select identifier

    Identification of the order of SQL execution, SQL execution from large to small


select_type:

  Indicates the type of query.

    (1) SIMPLE (simple SELECT, without using UNION or subqueries, etc.)

    (2) PRIMARY (the outermost query in the subquery, if the query contains any complex subparts, the outermost select is marked as PRIMARY)

    (3) UNION (the second or subsequent SELECT statement in UNION)

    (4) DEPENDENT UNION (the second or subsequent SELECT statement in UNION, depending on the query outside)

    (5) UNION RESULT (the result of UNION, all the options after the second select in the union statement)

    (6) SUBQUERY (the first SELECT in the subquery, the result does not depend on the external query)

    (7) DEPENDENT SUBQUERY (the first SELECT in the subquery, depends on the external query)

    (8) DERIVED (sub-query of SELECT, FROM clause of derived table)

    (9) UNCACHEABLE SUBQUERY (The result of a subquery cannot be cached, the first line of the outer link must be re-evaluated)


table:

  Table of output result sets


type:

  The access method to the table means that MySQL finds the required rows in the table, also known as "access type".

  Commonly used types are: ALL, index, range, ref, eq_ref, const, system, NULL (from left to right, performance from poor to good)

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

    index: Full Index Scan, the difference between index and ALL is that the index type only traverses the index tree

    range: retrieve only the rows in a given range, use an index to select rows

    ref: indicates the connection matching conditions of the above table, that is, which columns or constants are used to find the value on the index column

    eq_ref: Similar to ref, the difference is that the index used is a unique index. For each index key value, only one record in the table matches. In simple terms, the primary key or unique key is used as the association condition in the multi-table connection

    const, system: When MySQL optimizes a part of the query and converts it to a constant, these types of access are used. If you put the primary key in the where list, MySQL can convert the query to a constant. System is a special case of the const type. When the query table has only one row, use system

    NULL: MySQL decomposes the statement during the optimization process, and does not even need to access the table or index during execution. For example, selecting the minimum value from an index column can be done by a separate index search.


possible_keys:

  Indicate which index MySQL can use to find records in the table. If there is an index on the field involved in the query, the index will be listed, but not necessarily used by the query (the index that the query can use, if there is no index shows null )


key:

  Indicates the actual index used
    If no index is selected, the key is NULL. To force MySQL to use or ignore the indexes in the possible_keys column, use FORCE INDEX, USE INDEX, or IGNORE INDEX in the query.

key_len:

  Index field length

    Without loss of accuracy, the shorter the length, the better the ref:

  Comparison of columns and indexes

    The comparison of the column and the index indicates the connection matching conditions of the above table, that is, which columns or constants are used to find the value on the index column


rows:

  The number of rows scanned (estimated number of rows)
    estimates the number of rows in the result set, indicating that MySQL estimates the number of rows to read to find the required record based on table statistics and index selection. 
Extra:

  Description and description of implementation

    

    Using where : Without reading all the information in the table, you can obtain the required data only by indexing. This occurs when all the request columns of the table are part of the same index, indicating that the mysql server will retrieve rows in the storage engine Then filter

    Using temporary: indicates that MySQL needs to use a temporary table to store the result set, common in sorting and grouping queries, common group by; order by

    Using filesort : When the order by operation is included in the query, and the sort operation that cannot be completed using the index is called "file sorting"

    Using join buffer: Changing the value emphasizes that no index is used when obtaining the connection conditions, and the connection buffer is required to store intermediate results. If this value appears, it should be noted that depending on the specific situation of the query, it may be necessary to add an index to improve performance.

    Impossible where: This value emphasizes that the where statement will result in no matching rows (there is no result by collecting statistics).

    Select tables optimized away: This value means that only by using the index, the optimizer may only return one row from the aggregate function result

    No tables used: from dual or no from clause used in the Query statement

 

Guess you like

Origin www.cnblogs.com/xyzxy/p/12714018.html