Concept

Query Plan

The tree of operators PostgreSQL chose to execute a query, including scans, joins, sorts, and aggregations.

A query plan is the operator tree the planner produces from your SQL. Each node is a physical operation — a Seq Scan or Index Scan at the leaves, joins and sorts in the middle, an aggregate or limit at the root — with estimated row counts, costs, and (with ANALYZE) actual measurements.

Reading a plan, you start at the deepest node and work outward, since each node consumes its children. Pay attention to row count mismatches between estimated and actual, surprising scan choices, and any Sort/Materialize nodes that the planner inserted.

The plan is the single best diagnostic tool for query performance — most optimisation tasks start with EXPLAIN ANALYZE and an honest read of the result.