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.94.2) (envelope-from ) id 1v54RN-000vAI-Hk for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Oct 2025 15:44:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1v54QM-000Knq-Ko for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Oct 2025 15:43:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v54QM-000KnY-BR for pgsql-hackers@lists.postgresql.org; Sat, 04 Oct 2025 15:43:55 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1v54QK-000NRN-1o for pgsql-hackers@lists.postgresql.org; Sat, 04 Oct 2025 15:43:54 +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 594FhmiL1507625; Sat, 4 Oct 2025 11:43:48 -0400 From: Tom Lane To: David Rowley cc: PostgreSQL Developers Subject: Re: Teaching planner to short-circuit empty UNION/EXCEPT/INTERSECT inputs In-reply-to: References: <976130.1759375308@sss.pgh.pa.us> <1064547.1759418336@sss.pgh.pa.us> <1196118.1759438964@sss.pgh.pa.us> Comments: In-reply-to David Rowley message dated "Sat, 04 Oct 2025 16:55:56 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1507623.1759592628.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 04 Oct 2025 11:43:48 -0400 Message-ID: <1507624.1759592628@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Rowley writes: > I'm just considering the best fix and can think of two options: > 1) Move away from using varno=3D=3D0 in generate_append_tlist(). Use var= no=3D=3D1, or; > 2) Add handling in setrefs.c for T_Result to adjust varno=3D=3D0 Vars to > use varno=3D=3D1 vars. > The attached v4-0001 does #2, but wondering if #1 should be explored fir= st. I don't recall the details ATM, but if you poke around you will find multiple comments complaining about how that varno-zero convention is problematic or requires code to do something unusual. So I'd be in favor of trying to get rid of it, but I'm not entirely sure what to do instead, and the ramifications might be wider than you realize. In particular it's not clear to me why varno=3D=3D1 is better? As best I can recall without diving into code, the fundamental mismatch is that varno zero doesn't correspond to any RTE. It would be better if the Vars matched the subquery RTEs that are at the base of the set-operation nest, so that there were a useful referent as to where a Var came from. Arbitrarily setting varno=3D1 sounds like the worst case: we could neither identify a Var with a source subquery accurately, nor realize that its varno is phony. regards, tom lane