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 1tK7hj-0070tc-WB for pgsql-hackers@arkaria.postgresql.org; Sun, 08 Dec 2024 03:11:32 +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 1tK7hg-000ZNm-8Z for pgsql-hackers@arkaria.postgresql.org; Sun, 08 Dec 2024 03:11:29 +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 1tK7hf-000ZNa-Up for pgsql-hackers@lists.postgresql.org; Sun, 08 Dec 2024 03:11:29 +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 1tK7he-001bgz-5i for pgsql-hackers@lists.postgresql.org; Sun, 08 Dec 2024 03:11:28 +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 4B83BM3j3543368; Sat, 7 Dec 2024 22:11:22 -0500 From: Tom Lane To: Andres Freund cc: Andrei Lepikhov , =?utf-8?B?0JjQu9GM0Y8g0JbQsNGA0LrQvtCy?= , pgsql-hackers@lists.postgresql.org, p.petrov@postgrespro.ru 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: <3510224.1733609212@sss.pgh.pa.us> <3517444.1733613195@sss.pgh.pa.us> <07d035c5-0e40-45ee-9c78-60a5dc6e9fae@gmail.com> Comments: In-reply-to Andres Freund message dated "Sat, 07 Dec 2024 21:52:20 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3543366.1733627482.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 07 Dec 2024 22:11:22 -0500 Message-ID: <3543367.1733627482@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andres Freund writes: > On 2024-12-08 09:23:42 +0700, Andrei Lepikhov wrote: >> I think avoiding touching a hash table and an index under MergeJoin can= also >> be beneficial. > How would you get significant wins for mergejoins? You need to go throug= h both > inner and outer anyway? Yeah, sounds like nonsense to me too. The reason this can be a win for nestloop is that we perform a new scan of the inner relation for each outer row, and if we can skip an inner scan altogether then we're ahead. But mergejoin and hashjoin only scan each input once anyway, so I see no opportunity to save any scan work. It's barely possible that this is interesting for hash join because you could save scanning a hash list ... but frankly I don't believe there could be enough win there to justify additional mechanism. Hash join is in a world of hurt already if there are lots of duplicate hash codes. regards, tom lane