Re: BUG #19412: Wrong query result with not null constraint
Sergey Shinderuk <s.shinderuk@postgrespro.ru>
From: Sergey Shinderuk <s.shinderuk@postgrespro.ru>
To: Richard Guo <guofenglinux@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org, Tom Lane <tgl@sss.pgh.pa.us>,
David Rowley <dgrowleyml@gmail.com>
Date: 2026-02-18T12:03:30Z
Lists: pgsql-bugs
On 2/18/26 12:50, Richard Guo wrote:
> On Wed, Feb 18, 2026 at 10:51 AM Richard Guo <guofenglinux@gmail.com> wrote:
>> Exactly. I think this is because when adjust_appendrel_attrs_mutator
>> propagates the nullingrel bits from the parent rel's Var into the
>> translated Var, it loses the translated Var's original bits. Instead
>> of overwriting the translated Var's nullingrels, I think we should
>> merge them.
>>
>> --- a/src/backend/optimizer/util/appendinfo.c
>> +++ b/src/backend/optimizer/util/appendinfo.c
>> @@ -291,8 +291,11 @@ adjust_appendrel_attrs_mutator(Node *node,
>> var->varattno, get_rel_name(appinfo->parent_reloid));
>> if (IsA(newnode, Var))
>> {
>> - ((Var *) newnode)->varreturningtype = var->varreturningtype;
>> - ((Var *) newnode)->varnullingrels = var->varnullingrels;
>> + Var *newvar = (Var *) newnode;
>> +
>> + newvar->varreturningtype = var->varreturningtype;
>> + newvar->varnullingrels = bms_add_members(newvar->varnullingrels,
>> + var->varnullingrels);
>> }
>
> Here is a more readable version of the patch.
>
Thank you!
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?
--
Sergey Shinderuk https://postgrespro.com/
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