{
  "slug": "query-cardinality-estimation",
  "term": "Query cardinality estimation",
  "aliases": [
    "query result cardinality estimation",
    "row-count estimation"
  ],
  "definition": "Query cardinality estimation predicts the number of rows produced by a query or an intermediate query-plan operation.",
  "note": "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. [pg-explain]\n\nStatistics 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. [pg-stats]\n\nFor 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. [pg-estimates] [mysql-cardinality]\n\nAn 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. [hesela-coverage]",
  "related": [
    "predicate-selectivity",
    "postgresql-index-only-scan"
  ],
  "citations": [
    {
      "id": "pg-explain",
      "title": "PostgreSQL 18: Using EXPLAIN, output rows and repeated nodes",
      "url": "https://www.postgresql.org/docs/18/using-explain.html",
      "accessed": "2026-11-18"
    },
    {
      "id": "pg-stats",
      "title": "PostgreSQL 18: Statistics Used by the Planner, dependency limitations",
      "url": "https://www.postgresql.org/docs/18/planner-stats.html",
      "accessed": "2026-11-18"
    },
    {
      "id": "pg-estimates",
      "title": "PostgreSQL 18: Row Estimation Examples",
      "url": "https://www.postgresql.org/docs/18/row-estimation-examples.html",
      "accessed": "2026-11-18"
    },
    {
      "id": "mysql-cardinality",
      "title": "MySQL 8.4: SHOW INDEX, Cardinality estimates distinct values",
      "url": "https://dev.mysql.com/doc/refman/8.4/en/show-index.html",
      "accessed": "2026-11-18"
    },
    {
      "id": "hesela-coverage",
      "title": "Hesela: estimated rows versus read coverage",
      "url": "https://hesela.com/analyses/postgresql-toast-read-coverage/#estimated-rows",
      "accessed": "2026-11-18"
    }
  ],
  "status": "shipping",
  "advantages": [],
  "limitations": [],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-11-18",
  "provenance": [
    "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."
  ]
}
