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 1rTLb9-002CFk-V2 for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jan 2024 12:46:20 +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 1rTLb8-00F0tl-T5 for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jan 2024 12:46:18 +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 1rTLb8-00F0td-K5 for pgsql-hackers@lists.postgresql.org; Fri, 26 Jan 2024 12:46:18 +0000 Received: from mail-yw1-x1131.google.com ([2607:f8b0:4864:20::1131]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rTLb5-003p54-SP for pgsql-hackers@postgresql.org; Fri, 26 Jan 2024 12:46:18 +0000 Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-5ff7dd8d7ceso3326627b3.0 for ; Fri, 26 Jan 2024 04:46:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706273174; x=1706877974; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=RenGBkFEn8VTT8J90DyWXVzWbntLV22h/u9jigGyz00=; b=gBmriw1Up2Eovb0HpFj8v/wAINaOSLdlcjsuUhDpBlhoLylkBmxQQSy9JPDPUKnBbZ AiUCHnmQ7BBCEQRqzGj0DBh7eX3LxQiEY3fYXRkMQV92wYXdVCHVzVHpd0Crz3V/XDW9 nYJpJXjtbFBKi2fcya1NSCost+Aqv1Q9DR80NbIN6MU4co3J6RQgHn3q2HZqe5dLPdjf GMtwfv65F4V/qr/Z6phPTQOtpKQOiUsjZnnFrA7isgJVSVu1ZMQMAfPEuZPpdaDRFiSO dQoWPNMSEsA4Q0pPkTEXvs49baS89Ivw6GHFOByNg+jYDfjOiSkCoXQfo2ryUgqbPKRd L1iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706273174; x=1706877974; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RenGBkFEn8VTT8J90DyWXVzWbntLV22h/u9jigGyz00=; b=IWyT1mk4mmu3Mr0riKJxisHYDRFkZ4N03l0UPU4RfCyIjn0M85Orf3koOoXs2IKYMN IWFAKmsiiH2weL7lw+bXW49vo2RtrK1EU4X6tPJDIPD87TBTquh6nf0rhORhguAidX+j qurc4+lWcoFIZMyYjk5a0jPAUoypMPtA442YeHBErQiB4FppwyriYj5RLSfeiXEbFfhQ IRc7jE73hPNr2EaAyKGKhv8TsKImzu55XDL6YWbwDv7dyGgv2nfCbBznKfFAkW/q88cp sPf8Do32kp83/9E+ZKKbm8LnLAFPPMDI6WQt842VjdclaymDNQsLYoTkqeLVcSd+rPFI lqSQ== X-Gm-Message-State: AOJu0YzrFjywyKC3GjhtbXug1JsXxMk1Xocdv9/KpinrMPHem5MMFrK4 sO0UaZPEr+G5aGYYzSmTgsxQCehaYOrG5+1nB3WhF2Hgix929r725atNLMVbkYS7+adc+ptnFX3 HNtytzl67mf1AO9GqnJ1tqbiD2wE= X-Google-Smtp-Source: AGHT+IH2UXBXAhkN2tOksjSH2qs4PfJaCc6PQMnVC78YtjnVRnjB/zXMml1zwUuJWQPcQy5TIkJVUFdKzKJRevLRMyU= X-Received: by 2002:a0d:d40c:0:b0:5f1:2c90:405a with SMTP id w12-20020a0dd40c000000b005f12c90405amr1266653ywd.53.1706273174010; Fri, 26 Jan 2024 04:46:14 -0800 (PST) MIME-Version: 1.0 References: <247851.1668293143@sss.pgh.pa.us> <602d6b44-c734-4f7f-8999-99b6cac9bf17@yandex.ru> <00de47dd-7a38-4225-a47e-65a8ba6de8d3@yandex.ru> In-Reply-To: <00de47dd-7a38-4225-a47e-65a8ba6de8d3@yandex.ru> From: vignesh C Date: Fri, 26 Jan 2024 18:16:02 +0530 Message-ID: Subject: Re: A new strategy for pull-up correlated ANY_SUBLINK To: Alena Rybakina Cc: Andy Fan , pgsql-hackers , Tom Lane , Richard Guo , Andrey Lepikhov Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 13 Oct 2023 at 14:09, Alena Rybakina wro= te: > > On 13.10.2023 10:04, Andy Fan wrote: >> >> It seems to me that the expressions "=3D" and "IN" are equivalent here d= ue to the fact that the aggregated subquery returns only one value, and the= result with the "IN" operation can be considered as the intersection of el= ements on the left and right. In this query, we have some kind of set on th= e left, among which there will be found or not only one element on the righ= t. > > > Yes, they are equivalent at the final result, but there are some > differences at the execution level. the '=3D' case will be transformed > to a Subplan whose subPlanType is EXPR_SUBLINK, so if there > is more than 1 rows is returned in the subplan, error will be raised. > > select * from tenk1 where > ten =3D (select ten from tenk1 i where i.two =3D tenk1.two ); > > ERROR: more than one row returned by a subquery used as an expression > > However the IN case would not. > select * from tenk1 where > ten =3D (select ten from tenk1 i where i.two =3D tenk1.two ) is OK. > > > I think the test case you added is not related to this feature. the > difference is there even without the patch. so I kept the code > you changed, but not for the test case. > > Yes, I understand and agree with you that we should delete the last queri= es, except to one. > > The query below have a different result compared to master, and it is cor= rect. > > > Without your patch: > > explain (costs off) > +SELECT * FROM tenk1 A LEFT JOIN tenk2 B > ON B.hundred in (SELECT min(c.hundred) FROM tenk2 C WHERE c.odd =3D b.odd= ); > QUERY PLAN > -------------------------------------------------------------------------= ---- > Nested Loop Left Join > -> Seq Scan on tenk1 a > -> Materialize > -> Seq Scan on tenk2 b > Filter: (SubPlan 2) > SubPlan 2 > -> Result > InitPlan 1 (returns $1) > -> Limit > -> Index Scan using tenk2_hundred on tenk= 2 c > Index Cond: (hundred IS NOT NULL) > Filter: (odd =3D b.odd) > (12 rows) > > > After your patch: > > postgres=3D# explain (costs off) > SELECT * FROM tenk1 A LEFT JOIN tenk2 B > ON B.hundred in (SELECT min(c.hundred) FROM tenk2 C WHERE c.odd =3D b.odd= ); > > QUERY PLAN > -------------------------------------------------------------- > Nested Loop Left Join > -> Seq Scan on tenk1 a > -> Materialize > -> Nested Loop > -> Seq Scan on tenk2 b > -> Subquery Scan on "ANY_subquery" > Filter: (b.hundred =3D "ANY_subquery".min) > -> Aggregate > -> Seq Scan on tenk2 c > Filter: (odd =3D b.odd) > (10 rows) > > >>> I took the liberty of adding this to your patch and added myself as rev= iewer, if you don't mind. >> >> Sure, the patch after your modification looks better than the original. >> I'm not sure how the test case around "because of got one row" is >> relevant to the current changes. After we reach to some agreement >> on the above discussion, I think v4 is good for committer to review! >> >> >> Thank you!) I am ready to discuss it. > > > Actually I meant to discuss the "Unfortunately, I found a request..", loo= ks > we have reached an agreement there:) > > Yes, we have) Hi Andy Fan, If the changes of Alena are ok, can you merge the changes and post an updated version so that CFBot can apply the patch and verify the changes. As currently CFBot is trying to apply only Alena's changes and failing with the following at [1]: =3D=3D=3D Applying patches on top of PostgreSQL commit ID fba2112b1569fd001a9e54dfdd73fd3cb8f16140 =3D=3D=3D =3D=3D=3D applying patch ./pull-up.diff patching file src/test/regress/expected/subselect.out Hunk #1 succeeded at 1926 with fuzz 2 (offset -102 lines). patching file src/test/regress/sql/subselect.sql Hunk #1 FAILED at 1000. 1 out of 1 hunk FAILED -- saving rejects to file src/test/regress/sql/subselect.sql.rej [1] - http://cfbot.cputube.org/patch_46_4268.log Regards, Vignesh