MySQL: Explain Detailed

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_38569499/article/details/93141842

table of Contents

1、id

2、select_type

3、table

4、type

5、possible_keys、key和key_len

6、ref

7、rows

8、Extra


    explain command is usually used to analyze the reasons for slow implementation inefficient SQL statements. explain command to obtain the specified schedule MySQL implementation of the select statement, the select statement execution process, including how to connect the tables and the connections. Example:

1、id

    id represents the execution order, the larger the number performed before; in the case of equal size of the figures, from top to bottom performed. For example, in the example above, the bottom piece is executed first command id = 2.

   In the case of multi-table associated, id general association table is the same, but the first table top to bottom as the associated master table.

2、select_type

    SELECT indicates the type of common values ​​include:

  • SIMPLE: simple select query, the query does not contain sub-queries and union;
  • PRIMARY: complex query contains several sub-portion, the outermost query is marked as a PRIMARY;
  • UNION: If, after the second select occur in Union, will be marked as UNION; UNION if included in the FROM clause of a query, the outer layer will be marked as SELECT DERIVED;
  • UNION RESULT: The results acquired from the SELECT list UNION;
  • SUBQUERY: In sub-SELECT or WHERE clause included in the query;
  • DERIVED: derivatives, sub-queries included in the FROM list is marked DERIVED, MySQL will recursively these sub-queries, put the results into a temporary table.

3、table

    It refers to a set of output tables, i.e. the line in which the data is to obtain clause table.

4、type

    type refers to the type of scan. mysql5.7 type in the type of up to 14 species, common following categories:

  • all: full table scan;
  • index: order of the index scan the entire table, and the table return read data. The only thing that lies in this case faster than all places, according to an index scan is ordered;
  • range: there is a range of index scan, the equivalent of the range index type;
  • ref: Finding conditions are listed using the equal sign conditions and the use of non-unique index;
  • ref_eq: Scan ref unique index;
  • const: scanning a unique index value and the unique constant determined index column. At this point MySQL query optimization has become a constant in this section;
  •  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.

5、possible_keys、key和key_len

    May be used to represent the index, the index actually used and the length of the column index actually used.

6、ref

    Connecting the matching conditions are shown in Table, i.e. constant, or column which is used to find the index column values.

7、rows

    The number of times the inner loop, and can be understood as the number of lines scanned to find the data.

8、Extra

  • Using temporary: the temporary table instructions. MySQL temporary table is divided into in-memory and on-disk are two, priority use of in-memory temporary table, and when a temporary table is too large, it will be dumped as on-disk temporary tables. Temporary table typically handle more complex sorting, de-duplication, query packets, etc., or the association table;
  • Using index: the index covers the query. Covering index refers to the index can be used to return all of the fields required to select, without having to re-read the data back to the table;
  • Using where: MySQL server after storage engine return line, and then stored in the server instead of using the engine where filtering;
  • Using filesort: not saying we are ordered by a disk file, simply stated was a sort operation, using an index different from the sort. Then if a small amount of data that will be, if the amount of data will be sorted in the file memory sorting (sorted buffer for the sector) in;
  • Using index for group-by: MySQL support loose index scan a specific situation, for example, query the maximum and minimum packet in a packet;
  • Using index condition: use the index to find, but need to query the data back to the table, and filtered with other other conditions WHERE;
  • select tables optimized away: optimized execution plan is removed from the table and replaced by a constant, because MySQL read the corresponding values ​​from the internal table. Queries entire column indexed columns min (), max (), count () will this prompt.

Guess you like

Origin blog.csdn.net/weixin_38569499/article/details/93141842