pgsql: Fix expr_is_nonnullable() for IS DISTINCT FROM

From: Richard Guo <rguo(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix expr_is_nonnullable() for IS DISTINCT FROM
Date: 2026-10-10 01:53:48
Message-ID: E1xFMHU-000000011hR-2rzL@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix expr_is_nonnullable() for IS DISTINCT FROM

Commit c8d2f68cc taught expr_is_nonnullable() to treat a DistinctExpr
as never returning NULL. That is wrong: when neither input is NULL,
the result is NULL if the underlying equality operator returns NULL,
which nothing forbids. This could lead to wrong query results.

To fix, remove the DistinctExpr case, along with its test case.

While at it, test the relkind before calling has_subclass() in
var_is_nonnullable(), to avoid a useless syscache lookup for
partitioned tables.

Reported-by: Robert Haas <robertmhaas(at)gmail(dot)com>
Author: Richard Guo <guofenglinux(at)gmail(dot)com>
Discussion: https://postgr.es/m/CA+TgmoaLcsmc9weJr1yo1X1SwZJX1t4XXHj0SJzH8XztmN9Hdg@mail.gmail.com
Backpatch-through: 19

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5690aaa92cad8d34e769b973eb5ade856e3a468a

Modified Files
--------------
src/backend/optimizer/util/clauses.c | 12 ++----------
src/test/regress/expected/predicate.out | 10 ----------
src/test/regress/sql/predicate.sql | 4 ----
3 files changed, 2 insertions(+), 24 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Richard Guo 2026-10-10 02:01:32 Re: pgsql: Teach expr_is_nonnullable() to handle more expression types
Previous Message Tom Lane 2026-10-10 01:15:14 pgsql: Doc: remove some annoying zero-width spaces.