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 1tz5ij-00Eto0-QO for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Mar 2025 03:21:54 +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 1tz5ii-00Gs5L-5V for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Mar 2025 03:21:52 +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 1tz5ih-00Gs4y-Kt for pgsql-hackers@lists.postgresql.org; Mon, 31 Mar 2025 03:21:51 +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 1tz5ie-0023yp-1o for pgsql-hackers@postgresql.org; Mon, 31 Mar 2025 03:21:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1743391306; bh=W2nYA047Rqs5CF6LWeQdt6OBLkqsxvtwSshgG0YE2mw=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=n6BiJ2UoR0W8F1pDg1XOaDV/9+emgPhPBfDFWjwB7jvIbIxU/IIu4beVk7JHkyblR 2pB6P6YCqtSiPEpiPk8v4n505jvklEk7vdPTp9xnDqI+0AaM2BNsH6TF9pMuBHdHq0 Pfc7ozzxGpsgGYlakphZh8BkH9RPng7zniEg8yAmxNUWEZQef8nmOT1faQtXzXyUNj uxwi9EmQL1B4CCaS7wkj/ueb+o4IOEq8FsaUzoyLxQKEwaaflTU49X9A0gxPtzqYaB rTLPa/dzD3sKrWFtFyy5o2rK9Um3crKOfHf2T0rj+M/FI/r/z8PJ+Hq352Jxn2SHSA ed/bnAl/opa0w== 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 4E51260363; Mon, 31 Mar 2025 06:21:45 +0300 (MSK) Content-Type: multipart/alternative; boundary="------------kV5S6HDi2lGzHeaVWjHBSQV0" Message-ID: Date: Mon, 31 Mar 2025 06:21:43 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Memoize ANTI and SEMI JOIN inner To: David Rowley Cc: Andrei Lepikhov , 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, bases: 2025/03/31 02:41:00 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 01:22:00 #27841732 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. --------------kV5S6HDi2lGzHeaVWjHBSQV0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 31.03.2025 06:04, David Rowley wrote: > On Mon, 31 Mar 2025 at 15:33, Alena Rybakina wrote: >> I believe it's worth asserting that both inner_unique and single_mode are not true at the same time — just as a safety check. > add_paths_to_joinrel() just chooses not to populate inner_unique for > SEMI and ANTI joins because, as of today's master, it's pretty > pointless to determine that because the executor will short-circuit > and skip to the next outer tuple for those join types anyway. I don't > follow why having both these flags set would cause trouble. It seems > perfectly legitimate that add_paths_to_joinrel() could choose to set > the inner_unique flag for these join types, and if it did, the Assert > you're proposing would fail for no good reason. > I tend to agree with you that someone might set this flag to true for these join types in the future. 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(!extra->inner_unique&& (jointype== JOIN_SEMI|| jointype== JOIN_ANTI))     single_mode= true; -- Regards, Alena Rybakina Postgres Professional --------------kV5S6HDi2lGzHeaVWjHBSQV0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 31.03.2025 06:04, David Rowley wrote:
On Mon, 31 Mar 2025 at 15:33, Alena Rybakina <a.rybakina@postgrespro.ru> wrote:
I believe it's worth asserting that both inner_unique and single_mode are not true at the same time — just as a safety check.
add_paths_to_joinrel() just chooses not to populate inner_unique for
SEMI and ANTI joins because, as of today's master, it's pretty
pointless to determine that because the executor will short-circuit
and skip to the next outer tuple for those join types anyway. I don't
follow why having both these flags set would cause trouble. It seems
perfectly legitimate that add_paths_to_joinrel() could choose to set
the inner_unique flag for these join types, and if it did, the Assert
you're proposing would fail for no good reason.

I tend to agree with you that someone might set this flag to true for these join types in the future.

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 (!extra->inner_unique && (jointype == JOIN_SEMI || jointype == JOIN_ANTI))

    single_mode = true;
--
Regards,
Alena Rybakina
Postgres Professional
--------------kV5S6HDi2lGzHeaVWjHBSQV0--