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 1pxWtF-00080C-Ub for pgsql-bugs@arkaria.postgresql.org; Fri, 12 May 2023 17:49:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pxWtE-0007pt-In for pgsql-bugs@arkaria.postgresql.org; Fri, 12 May 2023 17:49:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pxWtE-0007pj-6U for pgsql-bugs@lists.postgresql.org; Fri, 12 May 2023 17:49:12 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pxWtB-001yGd-Jy for pgsql-bugs@lists.postgresql.org; Fri, 12 May 2023 17:49:10 +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 34CHn7oF1539385; Fri, 12 May 2023 13:49:07 -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: <1526312.1683912310@sss.pgh.pa.us> 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> Comments: In-reply-to Tom Lane message dated "Fri, 12 May 2023 13:25:10 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1539383.1683913747.1@sss.pgh.pa.us> Date: Fri, 12 May 2023 13:49:07 -0400 Message-ID: <1539384.1683913747@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I wrote: > This is correct AFAICS, and it's slightly cheaper, so an optimistic > conclusion would be that we're making a cost-based decision to use a plan > shape that the old code could not find for some reason. But these costs > are pretty close, within the "fuzz factor", so this might be a random > effect. It might be interesting to see if inserting unequal amounts > of data in the tables would drive the costs further apart, allowing > us to say that this code really does beat v15 in terms of planning > flexibility. Hah, indeed so: DROP TABLE IF EXISTS t1,t2,t3,t4 CASCADE; CREATE TABLE t1 AS SELECT true AS x FROM generate_series(0,1) x; CREATE TABLE t2 AS SELECT true AS x FROM generate_series(0,1) x; CREATE TABLE t3 AS SELECT true AS x FROM generate_series(0,1) x; CREATE TABLE t4 AS SELECT true AS x FROM generate_series(0,1000) x; ANALYZE t1,t2,t3,t4; EXPLAIN --(COSTS OFF) select * from t1 left join t2 on true left join t3 on t2.x left join t4 on t3.x; v15 (and HEAD) find a plan of cost 180, this patch finds one of cost 120. This test case is pretty artificial of course; can we come up with a more plausible query that we win on? regards, tom lane