Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tK2x2-006WeO-Ul for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Dec 2024 22:07:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tK2x0-00HBqb-As for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Dec 2024 22:06:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tK2x0-00HBqM-1K for pgsql-hackers@lists.postgresql.org; Sat, 07 Dec 2024 22:06:59 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tK2wy-001ZWc-7r for pgsql-hackers@lists.postgresql.org; Sat, 07 Dec 2024 22:06:58 +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 4B7M6qZO3510225; Sat, 7 Dec 2024 17:06:52 -0500 From: Tom Lane To: Andres Freund cc: =?utf-8?B?0JjQu9GM0Y8g0JbQsNGA0LrQvtCy?= , pgsql-hackers@lists.postgresql.org Subject: Re: Do not scan index in right table if condition for left join evaluates to false using columns in left table In-reply-to: References: Comments: In-reply-to Andres Freund message dated "Sat, 07 Dec 2024 16:37:32 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3510223.1733609212.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 07 Dec 2024 17:06:52 -0500 Message-ID: <3510224.1733609212@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andres Freund writes: > ISTM that it shouldn't be expensive to recognize this type of join claus= e and > pushes them down. While it could be done by the query's author, it seems= worth > handling this on our side. But maybe I'm missing something here? No, that condition *can't* be pushed down to the LHS scan, because its failure should not remove LHS rows from the output; it can only cause them to have nulls in the RHS columns. One could imagine that we split up the join filter conditions into "depends on RHS" and "doesn't depend on RHS" subsets, and make the nestloop plan node evaluate the latter set only once per LHS row, and then skip the inner-side scan when that condition fails. But this would be a bunch of new mechanism that's only useful for outer joins, only for rather hokey outer join conditions, and only for nestloop-type joins. I'm pretty dubious that it's worth the trouble -- not least because I don't recall anybody complaining about this before. regards, tom lane