Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pzJ5L-00051S-6v for pgsql-bugs@arkaria.postgresql.org; Wed, 17 May 2023 15:29:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pzJ5J-0006nx-PT for pgsql-bugs@arkaria.postgresql.org; Wed, 17 May 2023 15:29:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pzJ5J-0006no-Gq for pgsql-bugs@lists.postgresql.org; Wed, 17 May 2023 15:29:01 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pzJ5D-000MmX-Vv for pgsql-bugs@lists.postgresql.org; Wed, 17 May 2023 15:29:00 +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 34HFSqow3344782; Wed, 17 May 2023 11:28:52 -0400 From: Tom Lane To: Richard Guo cc: Robert Haas , Andrey Lepikhov , PostgreSQL mailing lists Subject: Re: Clause accidentally pushed down ( Possible bug in Making Vars outer-join aware) In-reply-to: References: <0b819232-4b50-f245-1c7d-c8c61bf41827@postgrespro.ru> <402433.1677524538@sss.pgh.pa.us> <2663884e-769a-b298-55b0-014c5a1ee55c@postgrespro.ru> <524303.1677538463@sss.pgh.pa.us> <999171.1677611407@sss.pgh.pa.us> <1526312.1683912310@sss.pgh.pa.us> <24! 89296.1684195396@sss.pgh.pa.us> <2766442.1684265014@sss.pgh.pa.us> <3014965.1684293045@sss.pgh.pa.us> Comments: In-reply-to Richard Guo message dated "Wed, 17 May 2023 16:29:54 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <3344780.1684337332.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 17 May 2023 11:28:52 -0400 Message-ID: <3344781.1684337332@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Richard Guo writes: > On Wed, May 17, 2023 at 11:10=E2=80=AFAM Tom Lane wr= ote: >> * I'm not terribly happy with 0004 as it stands, specifically the >> business of making build_join_rel recalculate pushed_down_ojrelids >> from scratch. Again, that's adding cycles to the mainline case to >> support an unusual case. It'd be better to make >> add_outer_joins_to_relids have an extra output that is the >> pushed_down_ojrelids set, and pass that forward. I ran out of time >> to make that happen today, though. > Actually I did that in this way before I invented the join_info_array > thing. See patch 'v2-0001-Adjust-outer-join-s-target-list.patch' in > https://www.postgresql.org/message-id/CAMbWs49CB3txv_s3SwC1L2h1DiUPAn%2B= v0-O4UFfg33b%2BHXNnTg%40mail.gmail.com > A little difference is that that patch makes add_outer_joins_to_relids > collect pushed down joins rather than pushed down ojrelids, so that in > build_joinrel_tlist we can just loop over pushed down joins rather than > the whole join_info_list. Ah, good idea. I made some cosmetic adjustments and pushed the lot. We still have a couple of loose ends in this thread: 1. Do we need the change in add_nulling_relids that I postulated in [1]? - bms_overlap(phv->phrels, context->target_relids)) + bms_is_subset(phv->phrels, context->target_relids)) The test case that made that fall over no longer does so, but I'm suspicious that this is still needed. I'm not quite sure though, and I'm even less sure about the corresponding change in remove_nulling_relids: - !bms_overlap(phv->phrels, context->except_relids)) + !bms_is_subset(phv->phrels, context->except_relids)) which I made up pretty much out of whole cloth. 2. Can we do anything to tighten make_outerjoininfo's computation of potential commutator pairs, as I speculated in [2]? This isn't a bug hazard anymore (I think), but adding useless bits there clearly does cause us to waste cycles later. If we can tighten that cheaply, it should be a win. 3. In general, it seems like what your fixes are doing is computing transitive closures of the commute_above relationships. I wonder if we can save anything by pre-calculating the closure sets. Again, I don't want to add cycles in cases where the whole thing doesn't apply, but maybe we'd not have to. regards, tom lane [1] https://www.postgresql.org/message-id/2489296.1684195396%40sss.pgh.pa.= us [2] https://www.postgresql.org/message-id/2766442.1684265014%40sss.pgh.pa.= us