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 1u0hQq-006AAH-EW for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Apr 2025 13:50:04 +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 1u0hQo-000NH8-2K for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Apr 2025 13:50:02 +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 1u0hQn-000NGy-NG for pgsql-hackers@lists.postgresql.org; Fri, 04 Apr 2025 13:50:01 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u0hQl-002vOv-2j for pgsql-hackers@postgresql.org; Fri, 04 Apr 2025 13:50:00 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-43948f77f1aso15039805e9.0 for ; Fri, 04 Apr 2025 06:49:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743774598; x=1744379398; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=t12fv5L75EIfBs4pxcu1k07cdXzudNxcS1CdPriLaPg=; b=UZuHuKRY6Gl0DCl30NM+EGhPBpPnWNQEQviUoObJSbRz7XR89d5MiUXfyUIvy/ElF/ UU0QdeEBizFYMEzf1nOCYKmJz7a8+A2pcrXlx83DialyiwgXxFnR88yUL2JxXGNM9zL3 E+oaNdoTpDoGRuQQneq/7JzvLdnW8E6DpZTBpW4tLdgMfZ3+Ecy6RV4Vr7jUXF/u+qk0 x1ZPXs2kkPrAbF9AkbFIoklrN3hv/2u5/Exv/OJSE+SFCNT+9uP81iBNYgiUU6P0heQr /Aiz9eebiAqHkY9B08L74HDIKRm9WleUAmwxfXjHSLLF43i6Fnc8vGX5NzMAdJ8V/5bz b4zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743774598; x=1744379398; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=t12fv5L75EIfBs4pxcu1k07cdXzudNxcS1CdPriLaPg=; b=X6kxJtFtDAx3rUq0MgU+0OLORKdl/k2X3lcSMYrvK3/ahIbOyXE/3SGigettWqaj8R H7RBFx0voZ90AeFWLJ9tmmv7PyhepFQwsRC11oil+ckROuPmYjIL9lyUZqVEFi5WSRFx u5ZGUSiTz/qmUsvLzFqioCbctoIHFZ9pJi06D/bJfeqYrKF5ltgnefYMhNMpzjgn8W3K 9GwtHr5zcYspmAD6tZ+We+IIPRi7nuKAn4SxGA0W27GPUzHl8ooNAhYmwwkhUSon/AJI hKOpWm6MvN33ga3wFp1VPa2OtwR9VwDrlC7jCyDYkwgzWp+hEPmxS3Rzer4Q619GSUAu jEdA== X-Gm-Message-State: AOJu0YxAd6uHFF7Sf5v6/rm4Lu3J/WUNmyOA6PVrghfLjLWAwsnL1KXk NhKZCbk/hl2JVil8hcTeN+5OU2+EufuRf4voggVldAPdDw4fMANY8VJ8OLzZcNT/CA== X-Gm-Gg: ASbGncv3aQu+7tYgS9amPBoU1VmPJokGmqYdzJKWtGEy2gn7UFtSHUjQwC1nmvvojjZ 8e6goAha8t9poDIC8X/NUR3iOCQvJCkMGT+1Hoei9TblaBEHzD9yc0rmIdLLuRh2vVFqZJrs9Gf wpOtdk40XHdp7zzli77dh3QDsQibtNHa8PauZp4O8FMz5CVNBFPmVJkPGjjYOP5qfMr6gMcUN+l Y6UNsplCiGoVC6cmPDZbcWxMOa8Lfg4WLe16/2UNZih92o/zaCykbk7ZG5Ie8Py+Rd0hVTtt6pp f9XcD3u5n+EPZ9Uj8imLc05QZDOENm7rnrWI4ZShUYoujXjuU1X+0/rmVmPkOAXQCTOeQPCrhfm f4w0= X-Google-Smtp-Source: AGHT+IH+qhrrgKxxzxkkmoV1SAZLzzkcE8lKu4x0mPa2wWJN/sKIA4kyD1soZbPN6q2wSswhFAGiOg== X-Received: by 2002:a05:600c:3109:b0:43c:f629:66f4 with SMTP id 5b1f17b1804b1-43ecf57edb7mr36249495e9.0.1743774597340; Fri, 04 Apr 2025 06:49:57 -0700 (PDT) Received: from [192.168.0.89] (84.123.232.230.dyn.user.ono.com. [84.123.232.230]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39c30226b39sm4329066f8f.85.2025.04.04.06.49.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Apr 2025 06:49:56 -0700 (PDT) Message-ID: Date: Fri, 4 Apr 2025 15:49:56 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Memoize ANTI and SEMI JOIN inner To: Richard Guo , David Rowley Cc: PostgreSQL-development References: <60bf8d26-7c7e-4915-b544-afdb9020011d@gmail.com> <95586c5d-2632-4f1c-bfb9-4c391f260de4@gmail.com> <1b356b61-3a2a-490a-bf9a-6340a1ec004a@gmail.com> Content-Language: en-AU From: Andrei Lepikhov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/1/25 09:18, Richard Guo wrote: > On Mon, Mar 31, 2025 at 7:33 PM Andrei Lepikhov wrote: >> and I don't get the case. As I see, ANTI/SEMI join just transforms to >> the regular join and it is still not the case. May you be more specific? > > Upthread, you said that a qual contained in ppi_clauses will also be > included in extra->restrictlist. I provided this example to show that > this is not true. And it seems to me that this discrepancy makes the > check I mentioned earlier not reliable in all cases. As I explained > earlier, this check could pass even if a restriction clause isn't > parameterized, as long as another join clause, which doesn't belong to > the current join, is included in ppi_clauses. This is not correct. Ok, keep aside the question of why we discuss it here. After second thought, I think the current check is correct at the moment. Looking into the inner_unique proving machinery, I see that the inner may be decided to be unique if: 1. It has a unique index on joining columns - in the case of NestLoop, these clauses inevitably go down as parameters. 2. degenerate case like x=1 where x is unique column - not our case, because x=1 goes down 3. DISTINCT clause - in this case, we can't transform the sublink at early stages, and using the already planned subquery --> upper rel clause will not be pushed to the unique inner. So, I see nothing criminal in this clause - it may be a little more specific to be sure we will be safe in case of improvements in the inner_unique proof logic or subquery parameterisation, but that's it. If my analysis is correct, we only need to change the comment. As usual, it would be nice to see an example of incorrect behaviour if I'm wrong. -- regards, Andrei Lepikhov