query-cardinality-estimation · shipping · also query result cardinality estimation, row-count estimation

Query cardinality estimation

Query cardinality estimation predicts the number of rows produced by a query or an intermediate query-plan operation.

PostgreSQL EXPLAIN rows describes a plan node's estimated output, not all tuples examined, heap fetches, bytes read or elapsed time. EXPLAIN ANALYZE executes the statement; for repeatedly executed nodes, actual rows are reported as a per-execution average, so inspect loops too. [1]

Statistics may be sampled or out of date. Estimates can also be inaccurate because a model misses relationships between columns. PostgreSQL extended statistics address supported cases; dependency statistics do not generally handle range predicates or incompatible constant combinations. They are not an exact-count guarantee. [2]

For a simple filter, estimated output is estimated input multiplied by estimated predicate selectivity. Distinct-value estimation answers another question: MySQL SHOW INDEX Cardinality is an estimate of distinct index values, not this query's output. [3] [4]

An estimate is not proof that an index is complete or that every stored payload byte was read and verified. Inspect the executed access path and the query's requested values separately. [5]

Relations

related
Predicate selectivity, Index-only scan (PostgreSQL)

Citations

  1. PostgreSQL 18: Using EXPLAIN, output rows and repeated nodes (accessed 2026-11-18)
  2. PostgreSQL 18: Statistics Used by the Planner, dependency limitations (accessed 2026-11-18)
  3. PostgreSQL 18: Row Estimation Examples (accessed 2026-11-18)
  4. MySQL 8.4: SHOW INDEX, Cardinality estimates distinct values (accessed 2026-11-18)
  5. Hesela: estimated rows versus read coverage (accessed 2026-11-18)
Sources & caveats
  • Primary-source synthesis scoped to PostgreSQL 18 and MySQL 8.4 documentation. The linked counting model uses constructed rows; it is not a PostgreSQL/MySQL planner run or a performance measurement.

JSON: /data/terms/query-cardinality-estimation.json

Published by Hesela team · Updated

Report a correction · Editorial standards · Reuse guidance

Cite this page
Hesela team. Query cardinality estimation. Hesela. 2026-11-18. https://hesela.dev/terms/query-cardinality-estimation/