Koskamo

Reading query plans with EXPLAIN

Document v1 · published by Koskamo editorial · updated 2026-10-04

Original source

PostgreSQL devises a query plan for each query it receives, and the EXPLAIN command shows what query plan the planner creates for any query. Plan costs are measured in arbitrary units determined by the planner's cost parameters; traditional practice measures costs in units of disk page fetches, with seq_page_cost conventionally set to 1.0 and the other cost parameters set relative to that. Each plan node reports an estimated startup cost, the time spent before the output phase can begin, and an estimated total cost, stated on the assumption that the node runs to completion, plus estimated row counts and the average width of output rows in bytes; the cost of an upper-level node includes the cost of all its child nodes. EXPLAIN ANALYZE actually runs the query, so any side-effects will happen as usual even though whatever results the query might output are discarded in favor of printing the EXPLAIN data; to analyze a data-modifying query without changing your tables, run it inside BEGIN and roll the command back afterwards. The measurement overhead added by EXPLAIN ANALYZE can be significant, especially on machines with slow gettimeofday() operating-system calls, and the pg_test_timing tool measures that overhead on your system. EXPLAIN results should not be extrapolated to situations much different from the one you are actually testing; results on a toy-sized table cannot be assumed to apply to large tables. Scope: PostgreSQL current-release documentation. Reviewed October 4, 2026.

Source and provenance

Original source
www.postgresql.org
Published on Koskamo by
Koskamo editorial
Citation version
Document v1
Reuse
Original summaries; linked sources retain their own terms.

The original source supplies the underlying information. Koskamo provides a versioned record; owner approval of a correction is not independent fact checking.