Re: Optimize IS DISTINCT FROM with non-nullable inputs - Mailing list pgsql-hackers

From Tender Wang
Subject Re: Optimize IS DISTINCT FROM with non-nullable inputs
Date
Msg-id CAHewXN=T9am6R-qTA9T6g3+bV9i7QOgmwvd_uepFpWpW9vjx_g@mail.gmail.com
Whole thread Raw
In response to Re: Optimize IS DISTINCT FROM with non-nullable inputs  (Richard Guo <guofenglinux@gmail.com>)
List pgsql-hackers
Richard Guo <guofenglinux@gmail.com> 于2026年1月27日周二 15:10写道:
>
> On Tue, Jan 27, 2026 at 11:32 AM Tender Wang <tndrwang@gmail.com> wrote:
> > Interesting optimization. I look through the v2-0001 patch. In the
> > commit message, it says:
> > ...
> >  This patch extends the optimization to cases where inputs are non-constant but
> >  proven to be non-nullable.  Specifically, "x IS DISTINCT FROM NULL"
> >  folds to constant TRUE if "x" is known to be non-nullable.
> > ...
> >
> > But I found that the case "x IS DISTINCT FROM NULL"  is converted to
> > NullTest in transformAExprDistinct().
> > It will be optimized in the "case T_NullTest:" not by this patch.
>
> Well, while it's true that the parser would do this transformation for
> "literal" NULLs, here we are talking more about "calculated" NULLs.
> Consider "not_null_col IS DISTINCT FROM (1 + NULL)".

Got it.

I looked through the v2-0002 patch. LGTM.


--
Thanks,
Tender Wang



pgsql-hackers by date:

Previous
From: Chao Li
Date:
Subject: Re: tablecmds: reject CLUSTER ON for partitioned tables earlier
Next
From: Mihail Nikalayeu
Date:
Subject: Re: Adding REPACK [concurrently]