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 1vt8io-0057Ls-0h for pgsql-bugs@arkaria.postgresql.org; Thu, 19 Feb 2026 18:25:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vt8in-005KZr-0W for pgsql-bugs@arkaria.postgresql.org; Thu, 19 Feb 2026 18:25:53 +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 1vt8im-005KZj-2y for pgsql-bugs@lists.postgresql.org; Thu, 19 Feb 2026 18:25:52 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vt8ik-00000000ApN-0XqJ for pgsql-bugs@lists.postgresql.org; Thu, 19 Feb 2026 18:25:52 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 61JIPmJ32663916; Thu, 19 Feb 2026 13:25:48 -0500 From: Tom Lane To: Richard Guo cc: Sergey Shinderuk , pgsql-bugs@lists.postgresql.org, David Rowley Subject: Re: BUG #19412: Wrong query result with not null constraint In-reply-to: References: <19412-1d0318089b86859e@postgresql.org> <60be6cb1-10de-4e24-82ce-b02650442d97@postgrespro.ru> Comments: In-reply-to Richard Guo message dated "Thu, 19 Feb 2026 10:49:44 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2663914.1771525548.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Thu, 19 Feb 2026 13:25:48 -0500 Message-ID: <2663915.1771525548@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Richard Guo writes: > On Wed, Feb 18, 2026 at 9:03 PM Sergey Shinderuk > 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