Re: BUG #19412: Wrong query result with not null constraint
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Richard Guo <guofenglinux@gmail.com>
Cc: Sergey Shinderuk <s.shinderuk@postgrespro.ru>,
pgsql-bugs@lists.postgresql.org, David Rowley <dgrowleyml@gmail.com>
Date: 2026-02-19T18:25:48Z
Lists: 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
Commits
-
Fix computation of varnullingrels when translating appendrel Var
- ec20a45528bf 16.13 landed
- bcaf1b5101c4 17.9 landed
- ed57c207c397 18.3 landed
- 691977d37037 19 (unreleased) landed
-
Fix IS [NOT] NULL qual optimization for inheritance tables
- 3af7040985b6 17.0 cited