Cheat Sheet: MySQL Explain
| Syntax |
|---|
| EXPLAIN <SELECT STATEMENT> |
| Columns in Result | |
|---|---|
| id | Statement Identifier |
| select_type | Which type of SELECT statement was given. |
| table | The name (or short handle) of the table in observation. |
| type | Describes how the MySQL Optimizer fits this table into the execution plan. |
| possible_keys | Lists the names of the indexes MySQL could use to optimize this particular statement. |
| key | Names the index that was actually used for this table in the given statement. |
| key_len | Length of the key in bytes. |
| ref | Which fields of the index are used (usefull for composite indexes). |
| rows | Estimation on how many rows will possibly be returned. |
| Extra | Useful hints and additions how the query will be executed. |
| Column: select_type | |
|---|---|
| SIMPLE | A query which uses only one table or joins tables. |
| PRIMARY | Outermost SELECT Statement in query using UNION or Subselect. |
| UNION | Any second or later table in a UNION statement. |
| DEPENDENT UNION | Any second or later table in a UNION depending on an outer SELECT. |
| UNION RESULT | Resulting derived table of a union. |
| SUBQUERY | SELECT Statement within a subquery |
| DEPENDENT SUBQUERY | SELECT Statement within a subquery that is depending on an outer SELECT. |
| DERIVED | Indicates that the FROM Clause is a subquery. |
| Column: type | |
|---|---|
| system | The table has only one value. |
| const | Evaluating a condition on a primary or unique key which leads to only one matching row. |
| eq_ref | For each combination of the other tables a row is read. Best possible join type fully utilizing primary or unique structures. |
| ref | For each combination of other tables all rows are read. Used when index in join are not unique. |
| ref_or_null | Like ref doing another pass to check for NULL values. |
| fulltext | Join uses a fulltext index. |
| index_merge | Indication that indexes are merged to join. Key field holds more than one index. |
| unique_subquery | Optimization in an subquery with an IN keyword having unique values. |
| index_subquery | Same as unique_subquery except that index values are non unique. |
| range | Statements with comparrision operators: LIKE, >=, >, <=, < IN, BETWEEN. |
| index | Sequential scan of index entries (includes covering index SELECT statements). |
| all | Indicates this table is accessed using a Full-Table Scan. This is the worst-possible outcome. |
| Column: Extra | |
|---|---|
| Distinct | Searching for distinct values, so search can be stopped after first matching row. |
| range checked for each record | More than indexes are found but MySQL can't decide which is the best and tries. |
| Select tables optimized away | Aggregation functions used on a single table with no group by. Only matching one result. |
| Using filesort | Another pass is needed for sorting the result (no information if in memory or on table). |
| Using index | All operations are done using the index. Accessing the data was not needed. |
| Using temporary | MySQL needs to create a temporary table to resolve the query. |
| Not exists | LEFT JOIN optimization where only one pass is needed to match the criteria. |
| Using where | A where clause is used to restrict the rows accessed. |