Skip to content

Reduce IS DISTINCT FROM with non-null inputs - #1623

Merged
tamnd merged 2 commits into
mainfrom
distinct-reduce
Nov 18, 2026
Merged

tamnd merged 2 commits into
mainfrom
distinct-reduce

Conversation

@tamnd

@tamnd tamnd commented Nov 18, 2026

Copy link
Copy Markdown
Owner

The DistinctExpr case of PostgreSQL 19's eval_const_expressions for an input that is not a constant (Fold::distinct in rupg-exec). It uses expr_is_nonnullable (Fold::nonnullable), which already exists: a column with a valid not-null constraint that no outer join makes null, a non-null constant, and COALESCE, GREATEST/LEAST or CASE over those.

Inputs Result
None can be null, one is a null constant true for IS DISTINCT FROM, false for IS NOT DISTINCT FROM (a false WHERE then makes the scan dummy)
None can be null the = operator of the expression, negated with its negator for IS DISTINCT FROM (<>); a NOT above it negates it back to =
One can be null, the other is a null constant IS NOT NULL, or IS NULL for IS NOT DISTINCT FROM

= lets index scans, hash joins and the equivalence classes use the condition.

Limits:

  • A row compared with a null constant keeps the DistinctExpr. PostgreSQL makes a NullTest with argisrow = false, which rupg's NullTest cannot express.
  • Only built-in operators are found for the = function.

Fixture connection/distinct_reduce.test, the output of PostgreSQL 19 for the same script. It covers the dist_tab cases of predicate.sql (except the row case above), plus text and varchar, two columns, an expression, COALESCE, a cast, NOT, an outer join in WHERE and in ON, the target list, and the hash join with enable_nestloop off.

Regression (changed lines of the diff, against the run after #1622): predicate 122 → 68, no other change in the targeted set. The other tests that use DISTINCT FROM show no change on a DISTINCT FROM line, and these pass: errors, domain, publication, opr_sanity, type_sanity, txid, xid, tsrf, create_index_spgist.

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 0512002 into main Nov 18, 2026
@tamnd
tamnd deleted the distinct-reduce branch November 18, 2026 21:47
@tamnd tamnd mentioned this pull request Nov 18, 2026
11 tasks
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