Databases
Intermediate
What is EXPLAIN Plan?
A database command that shows how the query planner will execute a SQL query, revealing join methods, scan types, and estimated costs.
EXPLAIN shows the execution plan the database optimizer chose for a query. In PostgreSQL, EXPLAIN ANALYZE actually runs the query and shows real execution times alongside estimates. Key elements include scan types (Seq Scan, Index Scan, Bitmap Scan), join methods (Nested Loop, Hash Join, Merge Join), sort operations, and cost estimates. Understanding EXPLAIN output is essential for query optimization — it reveals missing indexes, inefficient joins, and poor cardinality estimates. The BUFFERS option shows I/O statistics for identifying cache misses.