1. Syntax: EXPLAIN <SELECT STATEMENT>
Explain Column Definitions
id A sequential ID
select_type See SELECT_TYPE
table The table or alias
type See TYPE
possible_keys The possible indexes that could be used
key The actually index used
key_len See KEY_LEN
ref The columns (or constants) used
rows Approximate # of rows returned
Extra See EXTRA
EXTRA
const row not found The table was empty
Distinct Stops after first matching row
Full scan on NULL key No index lookup on a subquery
Impossible HAVING HAVING is always false
Impossible WHERE WHERE is false for all rows
Impossible WHERE
noticed after reading
const tables
WHERE is false for all rows after const (and system)
tables have been read
No tables used No FROM
Not exists LEFT JOIN optimization. Stops after first row match
Range checked for each
record (index map: N)
No good index found. One might be available as query
is processed
Select tables
optimized away
Only aggregate functions that can be resolved using an
index
Using filesort Sorting was needed rather than using an index
Using temporary During execution a temporary table was required
Using index The query was satisfied using only an index
Using where A WHERE clause exists
Using index for group-
by
GROUP BY or DISTINCT query can be satisfied with
an index
Using sort_union(...),
Using union(...),
Using intersect(...)
index_merge join type
Using join buffer Join was performed using an internal buffer
KEY_LEN
tinyint 1 byte TIMESTAMP 4 bytes
smallint 2 bytes DATETIME 8 bytes
INT 4 bytes CHAR(n) n bytes
BIGINT 8 bytes VARCHAR(n) n bytes + 2 bytes
DATE 3 bytes NULL possible +1 byte
Warning! Multibyte characters make byte!=character. UTF8 is 3 bytes
SELECT_TYPE
SIMPLE Simple SELECT
PRIMARY First SELECT in a UNION or outer query in a
subquery
UNION Second or later SELECT in a UNION
DEPENDENT UNION Second or later SELECT in a UNION
dependent on outer query
UNION RESULT Result of a UNION
SUBQUERY First SELECT in a subquery
DEPENDENT
SUBQUERY
First SELECT in a subquery. It is dependent
on an outer variable
DERIVED Derived table. SELECT subquery in FROM
clause
UNCACHEABLE
SUBQUERY
Result of subquery must be re-evaluated for
each other query row
TYPE
system The table has only one value (a system table)
const Exactly one matching row using PRIMARY or UNIQUE
eq_ref One row is matched from this table for each combination of rows
from the previous tables.
ref All matching rows from this table for each combination of rows
from the previous tables.
fulltext FULLTEXT index is used
ref_or_null ref with an additional pass for NULL values
index_merge Index merge optimization used
unique_subquery Optimized subquery handling in queries of the form value IN
(SELECT …) using PRIMARY or UNIQUE keys
index_subquery Like unique_subquery but with non-unique indexes
range KEY is compared against =, <>, >, >=, <, <=, IS
NULL, <=>, BETWEEN, or IN()
index Same as ALL but only the index is scanned
ALL Full table Scan