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 1o8jTD-0002qp-0C for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Jul 2022 14:24:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o8jTB-00036t-ON for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Jul 2022 14:24:05 +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 1o8jTB-00036k-FX for pgsql-hackers@lists.postgresql.org; Tue, 05 Jul 2022 14:24:05 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o8jT9-0007DT-2n for pgsql-hackers@lists.postgresql.org; Tue, 05 Jul 2022 14:24:04 +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 265EO0L11903935; Tue, 5 Jul 2022 10:24:00 -0400 From: Tom Lane To: Richard Guo cc: Pg Hackers Subject: Re: Making Vars outer-join aware In-reply-to: References: <830269.1656693747@sss.pgh.pa.us> Comments: In-reply-to Richard Guo message dated "Tue, 05 Jul 2022 19:02:38 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1903933.1657031040.1@sss.pgh.pa.us> Date: Tue, 05 Jul 2022 10:24:00 -0400 Message-ID: <1903934.1657031040@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Richard Guo writes: > For the query in the example > SELECT * FROM t1 LEFT JOIN t2 ON (t1.x = t2.y) WHERE foo(t2.z) > (foo() is not strict.) We want to avoid pushing foo(t2.z) down to the t2 > scan level. Previously we do that with check_outerjoin_delay() by > scanning all the outer joins below and check if the qual references any > nullable rels of the OJ, and if so include the OJ's rels into the qual. > So as a result we'd get that foo(t2.z) is referencing t1 and t2, and > we'd put the qual into the join lists of t1 and t2. > Now there is the 'varnullingrels' marker in the t2.z, which is the LEFT > JOIN below (with RTI 3). So we consider the qual is referencing RTE 2 > (which is t2) and RTE 3 (which is the OJ). Do we still need to include > RTE 1, i.e. t1 into the qual's required relids? How should we do that? It seems likely to me that we could leave the qual's required_relids as just {2,3} and not have to bother ORing any additional bits into that. However, in the case of a Var-free JOIN/ON clause it'd still be necessary to artificially add some relids to its initially empty relids. Since I've not yet tried to rewrite distribute_qual_to_rels I'm not sure how the details will shake out. regards, tom lane