{
  "slug": "predicate-selectivity",
  "term": "Predicate selectivity",
  "aliases": [
    "filter selectivity",
    "restriction selectivity"
  ],
  "definition": "Predicate selectivity is the fraction of a specified input population for which a predicate evaluates to true.",
  "note": "For a nonempty filter input, observed selectivity is matching rows divided by input rows. A planner instead estimates that fraction from statistics or assumptions. Multiplying it by the estimated input count gives an estimated output count, not a measurement. [pg-estimates]\n\nIn SQL WHERE, false and NULL predicate results are discarded. Rows containing NULL still belong to the input denominator; conditioning on non-NULL rows asks a different question. The empirical ratio is undefined for an empty input, although its output count is zero. [pg-where]\n\nCombining predicates by multiplying their marginal selectivities assumes independence. Identical per-column counts can coexist with different joint counts, so this product can underestimate or overestimate. [poosala-1997] A small matching fraction alone does not establish that an index is cheaper than a scan. [pg-multivariate] [pg-explain]\n\nMySQL SHOW INDEX Cardinality estimates distinct index values, a different quantity. [mysql-cardinality]",
  "related": [
    "query-cardinality-estimation",
    "covering-index"
  ],
  "citations": [
    {
      "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": "pg-where",
      "title": "PostgreSQL 18: WHERE, true versus false or null",
      "url": "https://www.postgresql.org/docs/18/queries-table-expressions.html#QUERIES-WHERE",
      "accessed": "2026-11-18"
    },
    {
      "id": "pg-multivariate",
      "title": "PostgreSQL 18: Multivariate Statistics Examples",
      "url": "https://www.postgresql.org/docs/18/multivariate-statistics-examples.html",
      "accessed": "2026-11-18"
    },
    {
      "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": "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"
    },
    {
      "id": "poosala-1997",
      "title": "Poosala and Ioannidis (VLDB 1997): Selectivity Estimation Without the Attribute Value Independence Assumption",
      "url": "https://www.vldb.org/conf/1997/P486.PDF",
      "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.",
    "VLDB 1997 Sections 2-7 support the marginal/joint distinction and MHIST/SVD context. The linked four-case model illustrates the principle; it does not reproduce those estimators or their accuracy."
  ]
}
