Re: BUG #19412: Wrong query result with not null constraint - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #19412: Wrong query result with not null constraint
Date
Msg-id 2663915.1771525548@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #19412: Wrong query result with not null constraint  (Richard Guo <guofenglinux@gmail.com>)
Responses Re: BUG #19412: Wrong query result with not null constraint
List pgsql-bugs
Richard Guo <guofenglinux@gmail.com> writes:
> On Wed, Feb 18, 2026 at 9:03 PM Sergey Shinderuk
> <s.shinderuk@postgrespro.ru> wrote:
>> I'm not familiar with the code, just curios. There is a long comment
>> above saying "You might think we need to adjust var->varnullingrels, but
>> that shouldn't need any changes." Doesn't it need an update?

> No, I don't think we need to update it.  That comment explains why
> varnullingrels do not require translation (since they are outer join
> relids, not baserel relids).  It's unrelated to what this patch does,
> which is about propagating varnullingrels into the translated Var.

I agree with this fix: I think the code is like it is simply because
it didn't occur to me that the child Vars could have any nullingrel
bits yet.  However, I don't agree that that comment needs no updates.
I suggest something like

-         * Below, we just propagate var->varnullingrels into the translated
-         * Var.
+         * Below, we just merge var->varnullingrels into the translated
+         * Var.  (We must merge not just copy: the child Var could have
+         * some nullingrel bits set already, and we mustn't drop those.)

Also, I think I'd then drop the comment you added adjacent to the
actual update; it seems redundant if the earlier comment says this.

I agree with back-patching to v16.  This particular example doesn't
misbehave in versions that don't have the drop-allegedly-redundant-
NOT-NULL-tests logic, but the varnullingrels are certainly wrong
all the way back, so possibly there are other examples that do
misbehave in v16.

            regards, tom lane



pgsql-bugs by date:

Previous
From: Kirill Reshke
Date:
Subject: Re: Error "could not access status of transaction" - version 14.21
Next
From: Richard Guo
Date:
Subject: Re: BUG #19412: Wrong query result with not null constraint