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 1v49tC-009ZnS-9g for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Oct 2025 03:21:54 +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 1v49tA-005xBX-CH for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Oct 2025 03:21: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.94.2) (envelope-from ) id 1v49tA-005xBO-2d for pgsql-hackers@lists.postgresql.org; Thu, 02 Oct 2025 03:21: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.96) (envelope-from ) id 1v49t7-000yOf-2d for pgsql-hackers@lists.postgresql.org; Thu, 02 Oct 2025 03:21:51 +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 5923Lmlc976131; Wed, 1 Oct 2025 23:21: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: Comments: In-reply-to David Rowley message dated "Thu, 02 Oct 2025 15:22:34 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <976129.1759375308.1@sss.pgh.pa.us> Date: Wed, 01 Oct 2025 23:21:48 -0400 Message-ID: <976130.1759375308@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Rowley writes: > In [1] there was a report that set operations didn't correctly detect > when inputs were provably empty sets. While this is not the bug that > the report claimed it to be, as it's just a missing optimisation, I > did decide to look at it to check if there was much performance to > gain from doing this. I'm kind of resistant to the amount of code this patch adds in comparison to the likely benefit. Sure, a badly written query can profit, but is it worth debugging and maintaining a couple hundred lines of code for that? The first few hunks of changes seem fine by this light, but I think you're expending too much effort on the EXCEPT-with-dummy-inputs cases. I'm wondering if it could be shortened a great deal by handling left-input-dummy and EXCEPT-ALL-with-right-input-dummy but leaving the EXCEPT-with-right-input-dummy case unimproved. regards, tom lane