13.8.2 EXPLAIN Syntax

    tbl_name [col_name | wild]

    [EXTENDED] SELECT select_options

The DESCRIBE and EXPLAIN statements are synonyms. In practice, the DESCRIBE keyword is more often used to obtain information about table structure, whereas EXPLAIN is used to obtain a query execution plan (that is, an explanation of how MySQL would execute a query). The following discussion uses the DESCRIBE and EXPLAIN keywords in accordance with those uses, but the MySQL parser treats them as completely synonymous.

Obtaining Table Structure Information

DESCRIBE provides information about the columns in a table:

mysql> DESCRIBE City;

DESCRIBE is a shortcut for SHOW COLUMNS. As of MySQL 5.0.1, these statements also display information for views. The description for SHOW COLUMNS provides more information about the output columns. See Section, “SHOW COLUMNS Syntax”.

By default, DESCRIBE displays information about all columns in the table. col_name, if given, is the name of a column in the table. In this case, the statement displays information only for the named column. wild, if given, is a pattern string. It can contain the SQL % and _ wildcard characters. In this case, the statement displays output only for the columns with names matching the string. There is no need to enclose the string within quotation marks unless it contains spaces or other special characters.

The DESCRIBE statement is provided for compatibility with Oracle.


Obtaining Execution Plan Information

The EXPLAIN statement provides information about how MySQL executes statements:

