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 1wzEDj-003tAw-0M for pgsql-hackers@arkaria.postgresql.org; Wed, 26 Aug 2026 14:03:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wzEDh-00Dbz5-0L for pgsql-hackers@arkaria.postgresql.org; Wed, 26 Aug 2026 14:03:13 +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 1wzEDg-00Dbyw-2c for pgsql-hackers@lists.postgresql.org; Wed, 26 Aug 2026 14:03:12 +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 1wzEDe-00000002WLW-3gBi for pgsql-hackers@lists.postgresql.org; Wed, 26 Aug 2026 14:03:11 +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 67QE2xYY696217; Wed, 26 Aug 2026 10:02:59 -0400 From: Tom Lane To: Richard Guo cc: 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> Comments: In-reply-to Richard Guo message dated "Wed, 26 Aug 2026 16:33:54 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <696215.1787752979.1@sss.pgh.pa.us> Date: Wed, 26 Aug 2026 10:02:59 -0400 Message-ID: <696216.1787752979@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Richard Guo writes: > I did some testing of planning time. Independent removals are fine, > even faster than before: 64 removable joins that each join directly to > t0 plan in 0.57 ms here vs 1.11 ms on master. They all go in the > first pass, and one extra pass over a single-rel query is cheaper than > the per-removal cleanup the old code did. Thanks for looking into this! > Chains of dependent joins are not fine though: > select t0.id from t0 > left join t1 on t0.nxt = t1.id > left join t2 on t1.nxt = t2.id > ... > left join t64 on t63.nxt = t64.id; > Only t64 can go in the first pass; t63 still looks needed because > attr_needed for t63.nxt includes t64's join, and we only find out > otherwise after the restart. So each link costs a full pass, and this > plans in 20.9 ms vs 1.98 ms on master. The gap widens quickly with > the chain length, and views built on views give the same shape. I'm skeptical that this example is a deal-breaker, because it seems quite artificial. Queries with this many relations would typically take a long time to plan. If we're somewhat slower to deal with the edge case where most of the joins vanish, is anyone really likely to notice? So I'm hesitant to add complexity in hopes of making the edge case faster. Especially since this is a bug fix that I'm hoping to back-patch; every dollop of complexity adds risk. regards, tom lane