Re: BUG #19412: Wrong query result with not null constraint

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Sergey Shinderuk <s(dot)shinderuk(at)postgrespro(dot)ru>, pgsql-bugs(at)lists(dot)postgresql(dot)org, David Rowley <dgrowleyml(at)gmail(dot)com>
Subject: Re: BUG #19412: Wrong query result with not null constraint
Date: 2026-02-20 09:57:12
Message-ID: CAMbWs4-Mv2jkyTj0VYNCVxVBJkr5NAzOsaDvAvFGe97B6eEStQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, Feb 20, 2026 at 3:25 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> 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.

Thanks for taking a look. I've updated the comments as suggested,

> 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.

... and then pushed and back-patched to v16.

Thank you, Sergey, for the report and the excellent self-contained
repro query. This is a great catch. (I'm curious how you found this
bug -- was it from a production query or a fuzzing tool?)

- Richard

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Ishan joshi 2026-02-20 10:39:28 Re: BUG #19396: Standby and DR site replication broken with PANIC: WAL contains references to invalid pages messge
Previous Message Hüseyin Demir 2026-02-20 06:52:33 Re: BUG #19393: pg_upgrade fails with duplicate key violation when CHECK constraint named *_not_null exists