Skip to main content
SQL

SQL EXPLAIN query plans: read what the database actually did

EXPLAIN turns query-performance guesses into a plan you can inspect. Focus on row estimates, scan types, joins, and actual timing before adding indexes.

Thien Nguyen
By Thien Nguyen
Updated May 23, 2026 · 1 min read

The query text is your request; the plan is the database's chosen route. Read the plan before changing indexes.

Short answer: run EXPLAIN to see intended operations and EXPLAIN ANALYZE in a safe environment to see actual timing and rows. Large estimate errors, broad scans, expensive sorts, and repeated nested-loop work are the useful clues.

EXPLAIN ANALYZE
SELECT * FROM orders WHERE account_id = 42 ORDER BY created_at DESC LIMIT 50;
Plan clueAsk
Seq ScanIs the filter selective enough for an index?
Rows mismatchAre statistics stale or predicates correlated?
SortCan an index match filter plus order?

EXPLAIN ANALYZE executes the query. Do not point it at a destructive statement on production merely to satisfy curiosity.

Measure, change one thing, and compare plans again.

Cover photo by Stanislav Kondratiev on Pexels.

References

Primary documentation and specifications checked when this article was last updated.

SQLDatabasesPerformance

Related articles

All articles