Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vsgHS-00DoNX-1A for pgsql-bugs@arkaria.postgresql.org; Wed, 18 Feb 2026 12:03:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vsgHQ-00Flwh-3A for pgsql-bugs@arkaria.postgresql.org; Wed, 18 Feb 2026 12:03:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vsgHQ-00FlwZ-1Q for pgsql-bugs@lists.postgresql.org; Wed, 18 Feb 2026 12:03:44 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vsgHM-00000001DAs-2QQ5 for pgsql-bugs@lists.postgresql.org; Wed, 18 Feb 2026 12:03:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1771416217; bh=PRCEoDGh9H6MAM7AqDOj+UlVMkma0fg4ar9MWVqDRtE=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=RQGqbQceWIETyFgHywcumdCMaskPKOD1uUpgB9kn/e1rxXPvsfsMeKeC/gSdRpYEn ZQGO54ozbfELpwfS2a9eDGVzJOZ23aHTCYkw2nEgJj5j5TragRYB/8VqG8gzjC7SU2 /is5kH5/Sg17sRSgeqC8j2fMR5ZcdQD4Eal5wiVt+UcdFVfMS4J5S0mT906mdDI6fL aooN3AbHfQp2ypPyM47HM9qb1hfr0bE8EizwvPBHGDNmpvRf6/dyxx2urPLD7gRMSx zv88mE2zV0/lIV5Y+gs5CLIdfT55Kgm5IqfcPkE5zlDCBcMwE2565qYxgJ2YmXDmKI zuyHTwWZGEfOw== Received: from [172.30.49.94] (debian11-template.l.postgrespro.ru [192.168.2.254]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: s.shinderuk@postgrespro.ru) by mail.postgrespro.ru (Postfix/465) with ESMTPSA id 69468603AC; Wed, 18 Feb 2026 15:03:37 +0300 (MSK) Message-ID: <60be6cb1-10de-4e24-82ce-b02650442d97@postgrespro.ru> Date: Wed, 18 Feb 2026 15:03:30 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #19412: Wrong query result with not null constraint To: Richard Guo Cc: pgsql-bugs@lists.postgresql.org, Tom Lane , David Rowley References: <19412-1d0318089b86859e@postgresql.org> Content-Language: en-US From: Sergey Shinderuk In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-KSMG-AntiPhishing: NotDetected, bases: 2026/02/18 10:33:00 X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2026/02/18 10:23:00 #28200586 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/18/26 12:50, Richard Guo wrote: > On Wed, Feb 18, 2026 at 10:51 AM Richard Guo 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/