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 1wo2jJ-000nzs-0a for pgsql-hackers@arkaria.postgresql.org; Sun, 26 Jul 2026 17:33:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wo2jH-009Qvi-1x for pgsql-hackers@arkaria.postgresql.org; Sun, 26 Jul 2026 17:33:35 +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 1wo2jH-009Qva-11 for pgsql-hackers@lists.postgresql.org; Sun, 26 Jul 2026 17:33:35 +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 1wo2jE-00000000SjR-3Ctb for pgsql-hackers@lists.postgresql.org; Sun, 26 Jul 2026 17:33:34 +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 66QHXQt73304319; Sun, 26 Jul 2026 13:33:26 -0400 From: Tom Lane To: Thom Brown cc: Richard Guo , 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> Comments: In-reply-to Thom Brown message dated "Sun, 26 Jul 2026 10:49:16 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3304317.1785087206.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 26 Jul 2026 13:33:26 -0400 Message-ID: <3304318.1785087206@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Thom Brown writes: > Thanks. I've re-tested against these and I'm no longer able to crash it. Thanks for testing! > And it still reports the same previous planner regression, although > thinks it may be considered acceptable. It also mentioned adding > jointype assertions because the hoisting code doesn't have any. Yeah, it occurred to me right after sending out the v3 patchset that fixup_selfjoin_jointree should have an Assert that it doesn't hoist anything above an outer join. Revised 0004 attached has that, and adds a test case based on this example. 0001-0003 still the same. As for the performance issue, I attach an 0005 that changes the self-join logic to perform as many removals as it can. I don't have a huge amount of faith in that, but I can't immediately see any reason why it's not okay. It seems almost certainly okay to perform SJE within groups of rels with different common OIDs, and even within a single group, an earlier removal doesn't look like it'd trash anything we are looking at. But it'd be worth running a fuzzer to see if any cases turn up where the patchset fails or gives different answers with/without 0005. regards, tom lane #text/x-diff; name=3D"v4-0001-Postpone-initialization-of-all_result_relids= -leaf.patch" [v4-0001-Postpone-initialization-of-all_result_relids-leaf.pa= tch] /home/tgl/pgsql/v4-0001-Postpone-initialization-of-all_result_relids-= leaf.patch #text/x-diff; name=3D"v4-0002-Perform-join-removal-by-editing-the-query-s-= joint.patch" [v4-0002-Perform-join-removal-by-editing-the-query-s-joint.pa= tch] /home/tgl/pgsql/v4-0002-Perform-join-removal-by-editing-the-query-s-j= oint.patch #text/x-diff; name=3D"v4-0003-Remove-dead-code-that-s-no-longer-needed-for= -join.patch" [v4-0003-Remove-dead-code-that-s-no-longer-needed-for-join.pa= tch] /home/tgl/pgsql/v4-0003-Remove-dead-code-that-s-no-longer-needed-for-= join.patch #text/x-diff; name=3D"v4-0004-Ensure-we-hoist-modified-quals-to-the-right-= join-.patch" [v4-0004-Ensure-we-hoist-modified-quals-to-the-right-join-.pa= tch] /home/tgl/pgsql/v4-0004-Ensure-we-hoist-modified-quals-to-the-right-j= oin-.patch #text/x-diff; name=3D"v4-0005-Allow-remove_useless_self_joins-to-remove-mu= ltipl.patch" [v4-0005-Allow-remove_useless_self_joins-to-remove-multipl.pa= tch] /home/tgl/pgsql/v4-0005-Allow-remove_useless_self_joins-to-remove-mul= tipl.patch