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 1x0hXe-004llx-0F for pgsql-hackers@arkaria.postgresql.org; Sun, 30 Aug 2026 15:33: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 1x0hXc-00DgQd-0j for pgsql-hackers@arkaria.postgresql.org; Sun, 30 Aug 2026 15:33:52 +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 1x0hXb-00DgQV-2l for pgsql-hackers@lists.postgresql.org; Sun, 30 Aug 2026 15:33:51 +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 1x0hXa-00000003AJN-09ES for pgsql-hackers@lists.postgresql.org; Sun, 30 Aug 2026 15:33:50 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 67UFXhOs492752; Sun, 30 Aug 2026 11:33:43 -0400 From: Tom Lane To: Richard Guo cc: Tender Wang , Thom Brown , Jacob Brazeal , pgsql-hackers@lists.postgresql.org Subject: Re: remove_useless_joins vs. bug #19560 In-reply-to: References: <1186816.1784573544@sss.pgh.pa.us> <2727652.1784997994@sss.pgh.pa.us> <2746010.1785014587@sss.pgh.pa.us> <2933135.1785032128@sss.pgh.pa.us> <3304318.1785087206@sss.pgh.pa.us> <3304418.1785087314@sss.pgh.pa.us> <3968565.1785170019@sss.pgh.pa.us> <3975112.1785176472@sss.pgh.pa.us> <670538.1786924698@sss.pgh.pa.us> <839346.1787765112@sss.pgh.pa.us> <954541.1787846010@sss.pgh.pa.us> <1147476.1787924590@sss.pgh.pa.us> <1708836! .1787974044@sss.pgh.pa.us> <250168.1788034245@sss.pgh.pa.us> Comments: In-reply-to Richard Guo message dated "Sun, 30 Aug 2026 15:50:20 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <492750.1788104023.1@sss.pgh.pa.us> Date: Sun, 30 Aug 2026 11:33:43 -0400 Message-ID: <492751.1788104023@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Richard Guo writes: > I looked at the patch. I noticed a couple of problems with putting > the preprocessed expression back into the subquery. Thanks for spotting these issues. > One is that preprocess_expression is not something we can run twice on > the same expression. Hmm, is that really true? I'm moderately certain that there are existing code paths where that can happen. I see your point about hitting !IsA(node, SubPlan) assertions, but I wonder if that's connected to the unpleasantly incestuous relationship between SS_process_sublinks and SS_replace_correlation_vars. That line of thinking probably leads to the same endpoint though, namely that we want to do this somewhere else. I'll study this some more and look for additional holes in it. > One consequence is that a not-yet-planned subquery can now contain > SubPlans, within a PHV of an upper query level. (This applies to your > patch as well.) This seems to be new. AFAICT, an unplanned subquery > never held SubPlans before. Fortunately, most of the tree walkers > that run on the subquery before SS_replace_correlation_vars replaces > the outer PHV with a Param cope with that. The exception is > flatten_join_alias_vars, which descends into every PHV and asserts on > SubPlans. I changed it to leave PHVs of upper levels alone; such a > PHV cannot contain join aliases of the level being flattened anyway. I wonder if we should try to run SS_replace_correlation_vars earlier. That's rather a scary change to be contemplating for stable branches though, precisely because of these hard-to-foresee interactions. regards, tom lane