PostgreSQL EXPLAIN Made Simple
The EXPLAIN command is your most powerful tool for understanding query performance. Yet most developers treat it like a foreign language — they know they should use it, but they do not know how to read the output.
Start with the basics: every EXPLAIN output is a tree of operations. Each node describes what the database is doing: scanning a table, filtering rows, joining results, sorting output. The numbers tell you the estimated cost, row count, and width.
Add ANALYZE to get actual execution times. Add BUFFERS to see I/O patterns. The gap between estimated and actual row counts is often the key to understanding slow queries — it means the planner's statistics are wrong, and a simple ANALYZE on the table may fix everything.
Select text to add a note.