Administration

SQL EXPLAIN

Show a query execution plan; output and options differ by engine.

Availability: Common SQL with references for SQL standard, MySQL/MariaDB, PostgreSQL, SQL Server, SQLite and Oracle Database; syntax and feature support vary by engine and version.中文

Syntax

EXPLAIN [options] query;

Examples

Example (standard-style syntax). Verify supported keywords in your database.

EXPLAIN SELECT id FROM orders WHERE customer_id = 12;

SQLite-oriented variant; dialect behaviour may differ.

EXPLAIN QUERY PLAN SELECT id FROM orders WHERE customer_id = 12;

Parameters, options and clauses

Option / clauseDescription
EXPLAINShow the optimizer's planned execution strategy.
ANALYZESome engines execute the statement and report actual statistics; this can run the query.
FORMATChoose plan output format where supported.
Catalog / information schemaInspect objects and definitions through system metadata.
Dialect / versionCheck the linked database manual for vendor-specific behaviour.

Dialect references

Safety note

Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.

Official reference ↗Back to directory