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 1pKPrZ-0003gJ-KH for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Jan 2023 20:25:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pKPrY-0006am-Gi for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Jan 2023 20:25:48 +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 1pKPrY-0006ad-7R for pgsql-hackers@lists.postgresql.org; Tue, 24 Jan 2023 20:25:48 +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 1pKPrW-0002LE-3v for pgsql-hackers@lists.postgresql.org; Tue, 24 Jan 2023 20:25:47 +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 30OKPgIt2315630; Tue, 24 Jan 2023 15:25:42 -0500 From: Tom Lane To: "David G. Johnston" cc: Hans Buschmann , Richard Guo , Pg Hackers , "Finnerty, Jim" Subject: Re: Making Vars outer-join aware In-reply-to: References: <830269.1656693747@sss.pgh.pa.us> <1903934.1657031040@sss.pgh.pa.us> <553080.1657481916@sss.pgh.pa.us> <1515100.1657633061@sss.pgh.pa.us> <2217146.1657721363@sss.pgh.pa.us> <2055912.1659383493@sss.pgh.pa.us> <1188905.1660666103@sss.pgh.pa.us> <1405792.1660677844@sss.pgh.pa.us> <1538543.1660683428@sss.pgh.pa.us> <2741731.1660848346@sss.pgh.pa.us> <1035990.1667261942@sss.pgh.pa.us> <2901865.1667685211@sss.pgh.pa.us> <4019771.1672155080@sss.pgh.pa.us> <323812.1672241806@sss.pgh.pa.us> <8c3a9f69b5d44373bdd35e640e59305c@nidsa.net> <2043562.1674506286@sss.pgh.pa.us> <2291988.1674588687@sss.pgh.pa.us> Comments: In-reply-to "David G. Johnston" message dated "Tue, 24 Jan 2023 12:47:53 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2315628.1674591942.1@sss.pgh.pa.us> Date: Tue, 24 Jan 2023 15:25:42 -0500 Message-ID: <2315629.1674591942@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Tue, Jan 24, 2023 at 12:31 PM Tom Lane wrote: >> select ... from t1 left join t2 on (t1.x = t2.y and t1.x = 1); >> >> If we turn the generic equivclass.c logic loose on these clauses, >> it will deduce t2.y = 1, which is good, and then apply t2.y = 1 at >> the scan of t2, which is even better (since we might be able to turn >> that into an indexscan qual). However, it will also try to apply >> t1.x = 1 at the scan of t1, and that's just wrong, because that >> will eliminate t1 rows that should come through with null extension. > Is there a particular comment or README where that last conclusion is > explained so that it makes sense. Hm? It's a LEFT JOIN, so it must not eliminate any rows from t1. A row that doesn't have t1.x = 1 will appear in the output with null columns for t2 ... but it must still appear, so we cannot filter on t1.x = 1 in the scan of t1. regards, tom lane