Re: pgsql: Teach expr_is_nonnullable() to handle more expression types

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Richard Guo <rguo(at)postgresql(dot)org>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pgsql: Teach expr_is_nonnullable() to handle more expression types
Date: 2026-10-07 01:30:29
Message-ID: CAMbWs48e=6t2zx7nyqR6=y6rh7NyL-VS13kQiTZD74XLj8v8dQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

On Tue, Oct 6, 2026 at 11:50 PM Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> Due to this commit, expr_is_nonnullable() claims that "IS DISTINCT
> FROM never returns NULL", but execExprInterp.c's implementation for
> EEOP_DISTINCT disagrees; when neither argument is NULL, it returns
> null if the underlying operator does. Two Claude-written test cases
> illustrating the problem are attached.

Right, thanks for the report. This needs an equality operator that
returns NULL for two non-null inputs, which I think is rare in
practice, but nothing forbids it, so I agree we should fix it.

I think we can just remove the T_DistinctExpr case from
expr_is_nonnullable(). An alternative is that we keep it, but only
when the operator is a btree equality operator, as such an operator
must not return NULL for non-null inputs. This keeps the optimization
for nearly all real-world cases.

What do you think?

- Richard

In response to

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2026-10-07 01:40:27 pgsql: reindexdb: Forbid index-level REINDEX with CONCURRENTLY and mult
Previous Message Tom Lane 2026-10-07 01:17:09 pgsql: Don't attempt to upgrade bpchar indexes from versions before 14.

Browse pgsql-hackers by date

  From Date Subject
Next Message shihao zhong 2026-10-07 01:31:53 Re: [PG19] eager aggregation gives wrong results because of bpchar_ops
Previous Message Peter Geoghegan 2026-10-07 01:23:24 Re: [PG19] eager aggregation gives wrong results because of bpchar_ops