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 1pRc26-0000pJ-Rw for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Feb 2023 16:50:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pRc25-0005ym-7E for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Feb 2023 16:50:25 +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 1pRc24-0005yc-To for pgsql-hackers@lists.postgresql.org; Mon, 13 Feb 2023 16:50:24 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pRc22-0003fi-Ej for pgsql-hackers@lists.postgresql.org; Mon, 13 Feb 2023 16:50:24 +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 31DGoHci1223374; Mon, 13 Feb 2023 11:50:17 -0500 From: Tom Lane To: Richard Guo cc: Justin Pryzby , pgsql-hackers@lists.postgresql.org, "Finnerty, Jim" Subject: Re: Making Vars outer-join aware In-reply-to: References: <1035990.1667261942@sss.pgh.pa.us> <2901865.1667685211@sss.pgh.pa.us> <4019771.1672155080@sss.pgh.pa.us> <323812.1672241806@sss.pgh.pa.us> <2043562.1674506286@sss.pgh.pa.us> <20230212235823.GW1653@telsasoft.com> Comments: In-reply-to Richard Guo message dated "Mon, 13 Feb 2023 15:33:15 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1223371.1676307017.1@sss.pgh.pa.us> Date: Mon, 13 Feb 2023 11:50:17 -0500 Message-ID: <1223373.1676307017@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Richard Guo writes: > Thanks for the report! I've looked at it a little bit and traced down > to function have_unsafe_outer_join_ref(). The comment there says > * In practice, this test never finds a problem ... > This seems not correct as showed by the counterexample. Right. I'd noticed that the inner loop of that function was not reached in our regression tests, and incorrectly concluded that it was not reachable --- but I failed to consider cases where the inner rel's parameterization depends on Vars from multiple places. > The NOT_USED part of code is doing this check. But I think we need a > little tweak. We should check the nullable side of related outer joins > against the satisfied part, rather than inner_paramrels. Maybe > something like attached. Agreed. > However, this test seems to cost some cycles after the change. So I > wonder if it's worthwhile to perform it, considering that join order > restrictions should be able to guarantee there is no problem here. Yeah, I think we should reduce it to an Assert check. It shouldn't be worth the cycles to run in production, and that will also make it easier to notice in sqlsmith testing if anyone happens across another counterexample. Pushed that way. Thanks for the report and the patch! regards, tom lane