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 1tz8ji-00FeCT-JJ for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Mar 2025 06:35:07 +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 1tz8jg-001Eze-W0 for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Mar 2025 06:35:04 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tz8jg-001EzV-GK for pgsql-hackers@lists.postgresql.org; Mon, 31 Mar 2025 06:35:04 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tz8jd-0025O5-1U for pgsql-hackers@postgresql.org; Mon, 31 Mar 2025 06:35:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1743402898; bh=GJ5PovoBm/M452mb9O2IbqDqRM615S+N3uHAPuZM2pU=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=TLIXQrTVKt8+Op+5aYsvCJ7Dtc5MnfOTd8qHvCXfbWfUes3Revk5spiLTAJF1XTFd 239oO30i1Z3HBzW0nt3+o6jxkOtRR6SY0oaHFC4v0iUrjr/fFXoj4X1rTwCnuXMmP6 4QQQYR1u/pzMr4beZQ7ZbadeMQ6MI14Jzra98Tic6CIkCL1AHd9YpUKNIHP5Ir45tW PwmOcCp0XRrdmHP/n9uH5N7/m5sgnlZE7O1pOeWjiOC2B8OjRJ9fS5uM/y8Fv051XW H8PMrssYuXkyzde+szo4jMljCKjTo1pTB0m5DoRAnCHKpv0lBi6S1N/YZSv4vL1HqF mNj2gfcdB3BaA== Received: from [10.0.85.1] (unknown [188.214.33.78]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: a.rybakina@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id E8C6C60445; Mon, 31 Mar 2025 09:34:56 +0300 (MSK) Content-Type: multipart/mixed; boundary="------------Fy0iN2nj6obAwnd3W2qzFPcM" Message-ID: <32524cd6-d069-476a-9989-76d7c695701b@postgrespro.ru> Date: Mon, 31 Mar 2025 09:34:54 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Memoize ANTI and SEMI JOIN inner To: David Rowley , Andrei Lepikhov Cc: PostgreSQL-development References: <60bf8d26-7c7e-4915-b544-afdb9020011d@gmail.com> <95586c5d-2632-4f1c-bfb9-4c391f260de4@gmail.com> <26e6dd23-ad56-4e00-8a24-c84b508267aa@postgrespro.ru> Content-Language: en-US From: Alena Rybakina In-Reply-To: X-KSMG-AntiPhishing: NotDetected X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2025/03/31 02:54:00 #27842368 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------Fy0iN2nj6obAwnd3W2qzFPcM Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 31.03.2025 06:33, David Rowley wrote: > On Mon, 31 Mar 2025 at 16:21, Alena Rybakina wrote: >> However, is it necessary to check that extra->inner_unique must be false for SEMI/ANTI joins here, or am I missing something? It looks a little confusing at this point. > If it is necessary, I don't see the reason for it. It was me that > worked on unique joins and I see no reason why a SEMI or ANTI join > couldn't be marked as unique. The reason they're not today is that the > only point of the unique join optimisation is so that during > execution, the join nodes could skip to the next outer tuple after > matching the current outer to an inner. If the join is unique, then > there are no more join partners to find for the current outer after > matching it up once. With SEMI and ANTI joins, we skip to the next > outer tuple after finding a match anyway, so there's no point in going > to the trouble of setting the inner_unique flag. > > I can't say definitively that we won't find a reason in the future > that we should set inner_unique for SEMI/ANTI joins, so I don't follow > the need for the Assert. > > Maybe you're seeing something that I'm not. What do you think will > break if both flags are true? > Actually, I was mainly confused by the code itself - the check seemed to contradict the explanation. It looked like we were enforcing that inner_unique must be false for SEMI/ANTI joins, even though it's not actually important for those join types. That’s why I originally proposed either adding an Assert or removing this flag from check altogether, just to make it more explicit. So, I agree with your explanation — by the definition of SEMI and ANTI joins, there's no need to set inner_unique, and also no need to assert against it. These joins skip to the next outer tuple once they find a match (or fail to find one, in the case of ANTI). I updated the diff, where I left changes only in the code comment. -- Regards, Alena Rybakina Postgres Professional --------------Fy0iN2nj6obAwnd3W2qzFPcM Content-Type: text/plain; charset=UTF-8; name="memoize.diff.no-cfbot" Content-Disposition: attachment; filename="memoize.diff.no-cfbot" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL29wdGltaXplci9wYXRoL2pvaW5wYXRoLmMgYi9z cmMvYmFja2VuZC9vcHRpbWl6ZXIvcGF0aC9qb2lucGF0aC5jCmluZGV4IGM3NTQwOGY1NTJi Li4yNTJjYjcxMjk0MyAxMDA2NDQKLS0tIGEvc3JjL2JhY2tlbmQvb3B0aW1pemVyL3BhdGgv am9pbnBhdGguYworKysgYi9zcmMvYmFja2VuZC9vcHRpbWl6ZXIvcGF0aC9qb2lucGF0aC5j CkBAIC03MjgsMTQgKzcyOCwxNiBAQCBnZXRfbWVtb2l6ZV9wY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