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

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

On Wed, Feb 18, 2026 at 10:51 AM Richard Guo <guofenglinux(at)gmail(dot)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.

- Richard

Attachment Content-Type Size
v1-0001-Fix-computation-of-varnullingrels-when-translatin.patch application/octet-stream 5.3 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Sergey Shinderuk 2026-02-18 12:03:30 Re: BUG #19412: Wrong query result with not null constraint
Previous Message Andrey Borodin 2026-02-18 08:58:03 Re: 17.8 standby crashes during WAL replay from 17.5 primary: "could not access status of transaction"