Re: Bug: var_is_nonnullable() gives wrong results for old/new in RETURNING - Mailing list pgsql-hackers

From Tender Wang
Subject Re: Bug: var_is_nonnullable() gives wrong results for old/new in RETURNING
Date
Msg-id CAHewXN=9mf6NCeHE=7jUVhM_Ur=oW8R7hgfQwcvyWCSLC8VERw@mail.gmail.com
Whole thread
In response to Bug: var_is_nonnullable() gives wrong results for old/new in RETURNING  (SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com>)
Responses Re: Bug: var_is_nonnullable() gives wrong results for old/new in RETURNING
List pgsql-hackers
SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com> 于2026年4月10日周五 02:43写道:
>
> Hi hackers,
>
> It appears the optimizer incorrectly simplifies old.<col> IS NULL to FALSE in RETURNING clauses when the underlying
columnhas a NOT NULL constraint. 
>
> The issue is that var_is_nonnullable() in clauses.c doesn't check Var.varreturningtype. It sees a NOT NULL column and
concludesthe Var can never be NULL. 
> But this assumption is wrong for old.* and new.* references. Because the old tuple doesn't exist on INSERT, and the
newtuple doesn't exist on DELETE 
> I am not super familiar with this area, so I attempted to fix this as in the patch attached.

Yes,  the current var_is_nonnullable() ignores this case.  The
attached patch seems ok to me.

Add Richard to the cc list. He may know more about this.
--
Thanks,
Tender Wang



pgsql-hackers by date:

Previous
From: Tatsuo Ishii
Date:
Subject: Re: Row pattern recognition
Next
From: "Shinoda, Noriyoshi (PSD Japan FSI)"
Date:
Subject: RE: [19] CREATE SUBSCRIPTION ... SERVER