Skip to content

What is a query execution plan?

A query execution plan describes the operations a database chooses to answer a query, helping teams investigate the time and resources an actual run consumes.

A query execution plan describes the operations a database chooses to answer a request for data. It can show how the database reads a table, whether it uses an index to find rows, and how it combines information from multiple tables. The optimizer makes that choice: it compares possible strategies using estimates of the work involved and statistics about the data. The plan helps investigate a slow query or heavy resource use, but its estimates are not actual measurements. In PostgreSQL, for example, EXPLAIN shows the expected plan; EXPLAIN ANALYZE actually runs the query and adds measured timing and row counts. The PostgreSQL documentation describes a plan as a tree of operations: each node receives data from other nodes or produces data for them. The format, commands, and information available depend on the database engine.

See also: Partitioning and clusteringTwo techniques that cut the data a query scans, and so its time and cost, in a cloud data warehouse.

What a plan actually shows

A sequential scan reads the table; an index lookup can locate a subset of rows. A scan alone does not mean the plan is wrong: when many rows are needed, reading the table can cost less than many index lookups. SQLite's query plan guide distinguishes SCAN from SEARCH and warns that the output format can change between releases.

In PostgreSQL, rows means the estimated rows emitted by a node, not the rows read: a filter can discard many of them. Estimated cost uses arbitrary units, not dollars or milliseconds, and a parent node's cost includes its children's. Comparing estimated and actual rows helps identify inaccurate estimates; planner statistics may be stale or fail to capture relationships between columns. Still, measure the outcome: a study comparing estimation methods integrated into PostgreSQL finds that the most widely used accuracy metric does not really reflect plan quality.

An enterprise example

A sales dashboard frequently queries orders by date range. The team compares the expected plan with a run under representative conditions and finds a large gap between estimated and returned rows. First it checks the statistics. After any change, it compares timing and, via PostgreSQL's BUFFERS option, the blocks read. If the issue is the amount of data examined, the team also considers partitioning and clustering or a materialized view, accounting for the cost of refreshing it.

Why it matters for decision makers

To evaluate a change, use the same query, parameters, and documented test conditions, and measure actual time and resource use. For a FinOps review, plan cost units must be paired with billing data, not mistaken for prices. The EXPLAIN reference warns that ANALYZE actually executes the statement and can modify data, so pick a suitable environment and permissions before testing. Measurement itself can add execution time.

Frequently asked questions

Statistics may be stale or fail to capture relationships between columns. Other properties of the query can also affect the estimate.

No. The length of the output describes the plan's shape, not the work done. Compare the operations and actual measurements instead.
  • Partitioning and clusteringTwo techniques that cut the data a query scans, and so its time and cost, in a cloud data warehouse.
  • FinOpsFinOps brings technology, finance, and business teams together to allocate technology spending, control its costs, and weigh them against business outcomes.
  • Materialized viewA materialized view stores the precomputed result of a query, making some reads faster at the cost of extra storage and the periodic work of keeping it current.
  • OLAP vs OLTPOLAP covers analysis across many records and OLTP covers day-to-day transaction processing; the two differ in read, write, and response-time requirements.
  • Data observabilityData observability monitors data health over time and flags anomalies in freshness, volume, structure, and values for the people who must act on the data.

See it in the universe

If it touches your company's data, getting that data in order is the first thing I do.

See Data Foundations

Or write to me.