SQL reference (MySQL and MariaDB dialects)

DESCRIBE and EXPLAIN

DESCRIBE lists the columns of a table; EXPLAIN gives a simple plan table. What each returns here and what is refused.

Syntax#

SQL
{ DESCRIBE | DESC } [db_name.]tbl_name

{ DESCRIBE | DESC | EXPLAIN } [FORMAT = TRADITIONAL] explainable_statement

explainable_statement:
    SELECT ... | ( SELECT ... ) | WITH ... | INSERT ... | UPDATE ... | DELETE ...

DESCRIBE tbl_name is the same as SHOW COLUMNS FROM tbl_name. EXPLAIN tbl_name (a table name instead of a statement) is also read as DESCRIBE.

Arguments#

NameMeaningDefault
FORMAT = TRADITIONALThe only plan format.TRADITIONAL

Remarks#

  • DESCRIBE returns Field, Type, Null, Key, Default, Extra. Extra shows auto_increment, VIRTUAL GENERATED, STORED GENERATED, INVISIBLE. Views, sequences (MariaDB) and temporary tables can be described. A column_name or pattern after the table is not in the grammar (use SHOW COLUMNS ... LIKE).
  • EXPLAIN answers MySQL's plan table (id, select_type, table, partitions, type, possible_keys, key, key_len, ref, rows, filtered, Extra) with one row per table. The values are what this front-end can state truthfully, not estimates: type is ALL, rows is 1, filtered is 100.00. There is no optimizer to report. For INSERT, UPDATE and DELETE the select_type is INSERT, UPDATE or DELETE.
  • Privileges: some privilege on the table (SELECT is named in the denial) for DESCRIBE; the privileges of the statement for EXPLAIN.

Not supported yet#

  • EXPLAIN ANALYZE, and EXPLAIN FORMAT other than TRADITIONAL (JSON, TREE): error 1235.
  • EXPLAIN of a statement other than SELECT, UNION, INSERT, UPDATE, DELETE (including WITH forms at run time): error 1235.
  • EXPLAIN FOR CONNECTION n, EXPLAIN with a column name.
  • MariaDB ANALYZE SELECT ... and ANALYZE FORMAT=JSON (error 1235).

Examples#

SQL
DESCRIBE t;
DESC t;
EXPLAIN SELECT * FROM t WHERE id = 1;
EXPLAIN FORMAT = TRADITIONAL DELETE FROM t WHERE id = 1;

See also#