Skip to content

constraint_exclusion = on excludes base relations - #1622

Merged
tamnd merged 3 commits into
mainfrom
exclusion-on
Nov 18, 2026
Merged

tamnd merged 3 commits into
mainfrom
exclusion-on

Conversation

@tamnd

@tamnd tamnd commented Nov 18, 2026

Copy link
Copy Markdown
Owner

More of relation_excluded_by_constraints (rupg-exec members()), after #1613, which covered tree members at partition.

  1. constraint_exclusion = on: the relation itself is a base relation that can be excluded. This covers a plain table, a table under ONLY, the parent of an INHERITS tree and a partitioned table.
    • include_noinherit is !inh, and include_notnull is !inh || partitioned, as in plancat.c.
    • An excluded relation has no member, so the planner makes it dummy (Result, Replaces: Scan on …, One-Time Filter: false). A join of it is dummy as well, and so is the inner side of a left join whose ON excludes it.
  2. Restrictions that refute one another: the immutable conditions, weakly refuted by themselves (a > 5 AND a < 3, a = 1 AND a = 2).
    • At on they exclude the relation.
    • At partition they exclude every member of a tree (not a table alone).
    • The test is lazy, so a plain-table scan at partition does not pay for it.
  3. NullTest reduction in constraints: as eval_const_expressions reduces with var_is_nonnullable, col IS NULL / IS NOT NULL of a validly not-null, non-row column of the table becomes a constant.
    • The AND/OR/NOT folding that follows folds only true and false. canonicalize treats a null arm as false, which is wrong for CHECK semantics.
    • So CHECK (a IS NULL OR b > 2) with a NOT NULL is b > 2.

Limit: a partition named directly at on does not yet add its partition constraint (include_partition).

Fixture connection/exclusion_on.test, the output of PostgreSQL 19 for the same script. It includes the two dummy-plan cases of predicate.sql, a plain table at partition and at on (refuted, kept, OR, contradictory, volatile, left join in WHERE and in ON, aggregate, UPDATE, DELETE), and an INHERITS tree with a NO INHERIT constraint, with and without ONLY, at both settings.

Regression (changed lines of the diff, against the run after #1620): partition_prune 2393 → 2332, join 2027 → 2003, predicate 146 → 122. No other test of the targeted set changed.

Part of the M7 regression work.

@tamnd tamnd added this to the M7: Procedures milestone Nov 18, 2026
@tamnd tamnd added kind/feature It does not do something that it must do. area/execution Operators, vectors, morsels, joins, aggregation and spill. labels Nov 18, 2026
@tamnd
tamnd merged commit aad6798 into main Nov 18, 2026
@tamnd
tamnd deleted the exclusion-on branch November 18, 2026 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/execution Operators, vectors, morsels, joins, aggregation and spill. kind/feature It does not do something that it must do.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant