Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pNUeV-0007T5-1O for pgsql-committers@arkaria.postgresql.org; Thu, 02 Feb 2023 08:09:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pNUeU-0006fp-0z for pgsql-committers@arkaria.postgresql.org; Thu, 02 Feb 2023 08:09:02 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pNOxI-0002uH-Jh; Thu, 02 Feb 2023 02:04:04 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pNOxG-0001FP-GB; Thu, 02 Feb 2023 02:04:03 +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 312241uP1446621; Wed, 1 Feb 2023 21:04:01 -0500 From: Tom Lane To: Richard Guo cc: pgsql-committers@lists.postgresql.org, PostgreSQL-development Subject: Re: pgsql: Remove over-optimistic Assert. In-reply-to: References: Comments: In-reply-to Richard Guo message dated "Thu, 02 Feb 2023 09:51:58 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1446619.1675303441.1@sss.pgh.pa.us> Date: Wed, 01 Feb 2023 21:04:01 -0500 Message-ID: <1446620.1675303441@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Richard Guo writes: > On Thu, Feb 2, 2023 at 8:40 AM Tom Lane wrote: >> In commit 2489d76c4, I'd thought it'd be safe to assert that a >> PlaceHolderVar appearing in a scan-level expression has empty >> nullingrels. However this is not so, as when we determine that a >> join relation is certainly empty we'll put its targetlist into a >> Result-with-constant-false-qual node, and nothing is done to adjust >> the nullingrels of the Vars or PHVs therein. (Arguably, a Result >> used in this way isn't really a scan-level node, but it certainly >> isn't an upper node either ...) > It seems this is the only case we can have PlaceHolderVar with non-empty > nullingrels at scan level. So I wonder if we can manually adjust the > nullingrels of PHVs in this special case, and keep the assertion about > phnullingrels being NULL in fix_scan_expr. I think that assertion is > asserting the right thing in most cases. It's a pity to lose it. Well, if we change the nullingrels of the PHV in the Result, then we will likely have to loosen the nullingrels cross-check in the next plan level up. That doesn't seem like much of an improvement. Keeping the Result's tlist the same as what we would have generated for a non-dummy join node seems right to me. We could perhaps use a weaker assert like "phv->phnullingrels == NULL || we-are-at-a-dummy-Result", but I didn't think it was worth passing down the extra flag needed to make that happen. (Also, it's fair to wonder whether setrefs.c actually knows whether a Result arose this way.) Also, there are other places in setrefs.c that are punting on checking phnullingrels. If we don't tighten all of them, I doubt we've moved the ball very far. regards, tom lane