Section: explain and analysis

Explain a SELECT query

sql
sql
EXPLAIN SELECT * FROM orders WHERE user_id = 42 ORDER BY created_at DESC LIMIT 20;
Explanation

`EXPLAIN` is the first stop when a query is unexpectedly slow.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing explain and analysis
Explain a currently running connection
Obtain the plan for a statement running in another session.
OpenIn sheetsqlsame section
Run EXPLAIN ANALYZE
Execute the query and include actual timing information.
OpenIn sheetsqlsame section
Refresh table statistics
Update optimizer statistics for a table.
OpenIn sheetsqlsame section
Optimize a table
Reorganize table storage and update index statistics for supported engines.
OpenIn sheetsqlsame section
Create a simple index
Add an index for a frequently filtered column.
Create a composite index
Index multiple columns in left-to-right order.