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.96) (envelope-from ) id 1wA3BR-00218m-23 for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Apr 2026 09:57:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wA3BP-00GSmf-0G for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Apr 2026 09:57:19 +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.96) (envelope-from ) id 1wA3BO-00GSmX-2S for pgsql-hackers@lists.postgresql.org; Tue, 07 Apr 2026 09:57:19 +0000 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wA3BM-000000014d1-3WAq for pgsql-hackers@lists.postgresql.org; Tue, 07 Apr 2026 09:57:18 +0000 Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-66bb7e098b1so5072824a12.3 for ; Tue, 07 Apr 2026 02:57:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775555836; cv=none; d=google.com; s=arc-20240605; b=In8b7nfmgCQhPNzJPzi7xmENy88QnC/XuIWbqdW8eetXXTkO4SdN5eeEmxSZ2ZztEw YHY3H1LFlCsXDZjYSIcMqevjvHhY9P+KxcnBDS7wd0C6h1xyY8W+mn0sqezz2cqHkr5o +a9K6hxlp/wTZDj7TnUTrFTXnThmYGryebb+fUyoHDsJw6KTzyQv5lJgGur4FNF+sdu3 50T1QehOtfoxlIuLlJgS83FeQvcsuNQSlZ0BRnLoZ9Q/T93ilvhsNAk4ry2SS7ACHtLl C12UePBa/YmmOd18RwpjDbjT0iNUQxYD9mwhV1hMSROqyxX63KFWXV1UwlyU4TGP8fxW y1Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=g0aB++taM8jwl08QOlqe2bH0pFYfO77CO5p3KTjCmTQ=; fh=NOo30AAV3JZ2gV+RE/nn4WjuTPJNrVMgF4c+LPp6+pw=; b=hCgdtR9OI3kKH1W8pumNfKjJM4LUjTAjGjcMkKe+G5wNlXCeQTbNG8hT55uN7C39HA ptygRnhmYOGaiDnDo0hlStufRsCyv9jryLSsgBoTO94q1VdZut18HKDPd6xgdvbbJQpk HX474kVsF+agxQMcugrvpR8omGlRuAnKKApO8a5pE9/JKT29F8kiM8FeL3gxXr3XInzi MwyfbYrHakGxI23EVyjWHNB9zwDZxYRVa4TrPl3lZ68gYc5TeJHljsKblVsNYL+9+fY/ sYLMYeZhLwM4v+19c6HSVNCqdKQeeuN6fPfD7BzKj8dfPLQx77MbbDQ+CLgNOSc7jO6L t/uw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775555836; x=1776160636; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=g0aB++taM8jwl08QOlqe2bH0pFYfO77CO5p3KTjCmTQ=; b=iSVYPJcnC5nti3HfIpzr/qauJU38n+6JL8JMVs3AQ7gqqFfxs/7B705B4iCd/aVFav cQ36nfpVt+jqjQYYGGhNE8tWKrV2ZEAjQIR56UFcnOtqtQreAwKHnH5TSJWSfa+4c0HA 10zSxKBJ5W2JQlXRdPKVEcFSL4H3DrNkmyaCu230aWaLxmAoOn6v9vuwERJQwuOz2JCe 5btABukekIZpSEGcr7wkg86GmcWZGAOj4v1zu2ICaYPas1N26fBCGQj0TZ/N5NYH7Tlc tvq8Mt3AiSdD5L/pASw+ZQNbB7v6sP2chdXJeiyF/fNxZFfYBWY46uxX2fY+FZMNUNct jCqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775555836; x=1776160636; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=g0aB++taM8jwl08QOlqe2bH0pFYfO77CO5p3KTjCmTQ=; b=K7uyXxqVmGrrq1zIZLS0ay+uAtCnqsJnjR/d9xuE4zgCqemj5ld8lrRauNyUe6CJvR YNU5kxb4s4ixn64Hb284xRyrcNsjp477g7mB1mx3mcEd56qazBXu5vLnTI8aNE8Mh0rW E7QkN+tXl/bn7bdvjO26oOKBJxdMGBIqI/8kbVwt/sysHjyh0HFCkIGTdibkCloSSK9D gYzwq//1ZS5Ezx8Ya6JV+gBjTEmNUQYmTb4SLFJYqD1K5hStmyj0Juna92Oly1KGX05b 0aJTOaexIEnWkxNgRbmJyZBcPN3CBg5CAfhtY3PEx6OmjiGQE1F5Zexw16KWywtQ7S74 VuPQ== X-Gm-Message-State: AOJu0Yxkhi7QZ019LzI3fmRskIukBsvkEG5f6snCJIniSu1nbk/78Q1+ S0kBAW6l/MoxbrGXSWumj0UZ0igzTz1vQ6iJoACgZ6VTwUe/8HR0wu35X9BbaAmtvu/1TOVC/Tq b0eIqpEJdoXb891o90GOoSOheb1j51uM= X-Gm-Gg: AeBDiesYlVjxqq96IgY88iznLvE/AfL5vPJHwdPij6YE826bqgRCBPuO+I32ZVADteh Vpc1gZiTtG9OWIeM6fr44beMpYvHLp/YPuyvFrCC4CJ1mnMLDKdKvrI6qUzQyLL6uqafKDd04df yBauJzxPISz3qtRTDVIK7yd4R520ut1bF+OK2DlVbAfeMUS1wuu5tl6Py9TM7cQpb+uQ4UOUI7J Rr9tzpeTf96m5DbkvDEfoKE/NsOMK2If9cLX6m9CTjaJwoGloS5LgoAoOxi0B0iy7rJQUbzCnFC yt6fCU+DKSkEwBT0EommdTQAmhJwIDPt7LTvKw== X-Received: by 2002:a05:6402:5c8:b0:66f:7501:e665 with SMTP id 4fb4d7f45d1cf-66f7501f07amr105754a12.17.1775555835675; Tue, 07 Apr 2026 02:57:15 -0700 (PDT) MIME-Version: 1.0 References: <7f6439c7-e5a7-4d0c-82c9-4087794cd9d0@gmail.com> In-Reply-To: <7f6439c7-e5a7-4d0c-82c9-4087794cd9d0@gmail.com> From: wenhui qiu Date: Tue, 7 Apr 2026 17:57:03 +0800 X-Gm-Features: AQROBzA8JZWkJ3xOwSr_oSPSOT61MxnZTqyxGKH--VAtmTRYm8RIsvASMcAt44g Message-ID: Subject: Re: Clean up remove_rel_from_query() after self-join elimination commit To: Richard Guo Cc: Pg Hackers Content-Type: multipart/alternative; boundary="000000000000dd4975064edbce0d" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000dd4975064edbce0d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable HI Richard > While working on reusing remove_rel_from_query() for inner-join > removal, I noticed that the function is in pretty rough shape. The > self-join elimination (SJE) commit grafted self-join removal onto > remove_rel_from_query(), which was originally written for left-join > removal only. Thanks for working on this. I see there are already asserts here for the mode split and for ojrelid validity. What I had in mind was slightly narrower: making the joinrelids contract explicit as well.As far as I can tell, the existing asserts would still allow an outer-join call with joinrelids =3D=3D NULL, even though joinrelids is later used in the outer-join-specific PHV handling. I wonder if something like ```c Assert(!is_outer_join || joinrelids !=3D NULL); Assert(!is_self_join || joinrelids =3D=3D NULL); Thanks On Tue, Apr 7, 2026 at 4:22=E2=80=AFPM Andrei Lepikhov = wrote: > On 06/04/2026 10:11, Richard Guo wrote: > > Thoughts? > Thanks for your efforts! > > The main goal of the SJE feature was to find common ground within the > community - to come up with a solution that everyone could get behind on > whether to allow optimisations that address redundant queries and reduce > query tree complexity in early planning stages. So, some code roughness > was ok. > > I looked through your code, though maybe not as deeply as this part of > the planner deserves. Overall, it looks good, and I didn=E2=80=99t spot a= ny > obvious problems, but I do have a few comments. We added some > =E2=80=98redundant=E2=80=99 checks with future optimisations in mind, so = others can rely > on these functions to remove tails from query structures or to error if > something was left behind. > > You explicitly write: > > =E2=80=98Each specific caller remains responsible for updating any remain= ing > data structures required by its unique removal logic=E2=80=99 > > that differs from the initial idea. At the same time, by the end of SJE > development, I wasn=E2=80=99t so sure we could invent a universal approac= h to > guarantee the cleanup of the query tree - mostly because of the inherent > volatility of the PlannerInfo structure and because we had not agreed to > make the parse tree a read-only structure. > > So, I=E2=80=99m fine with the changes in this patch. > > -- > regards, Andrei Lepikhov, > pgEdge > > > --000000000000dd4975064edbce0d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
HI=C2=A0Richard
> While working on reusing remove_r= el_from_query() for inner-join
> removal, I noticed that the function= is in pretty rough shape.=C2=A0 The
> self-join elimination (SJE) co= mmit grafted self-join removal onto
> remove_rel_from_query(), which = was originally written for left-join
> removal only.
Thanks for working on this.

I see there are already ass= erts here for the mode split and for ojrelid validity. What I had in mind w= as slightly narrower: making the joinrelids contract explicit as well.As fa= r as I can tell, the existing asserts would still allow an outer-join call = with joinrelids =3D=3D NULL, even though joinrelids is later used in the ou= ter-join-specific PHV handling.
I wonder if something like

```cAssert(!is_outer_join || joinrelids !=3D NULL);
Assert(!is_self_join |= | joinrelids =3D=3D NULL);



=
Thanks=C2=A0

On Tue, Apr 7, 2026 at 4= :22=E2=80=AFPM Andrei Lepikhov <lep= ihov@gmail.com> wrote:
On 06/04/2026 10:11, Richard Guo wrote:
> Thoughts?
Thanks for your efforts!

The main goal of the SJE feature was to find common ground within the
community - to come up with a solution that everyone could get behind on whether to allow optimisations that address redundant queries and reduce query tree complexity in early planning stages. So, some code roughness was ok.

I looked through your code, though maybe not as deeply as this part of
the planner deserves. Overall, it looks good, and I didn=E2=80=99t spot any=
obvious problems, but I do have a few comments. We added some
=E2=80=98redundant=E2=80=99 checks with future optimisations in mind, so ot= hers can rely
on these functions to remove tails from query structures or to error if something was left behind.

You explicitly write:

=E2=80=98Each specific caller remains responsible for updating any remainin= g
data structures required by its unique removal logic=E2=80=99

that differs from the initial idea. At the same time, by the end of SJE development, I wasn=E2=80=99t so sure we could invent a universal approach = to
guarantee the cleanup of the query tree - mostly because of the inherent volatility of the PlannerInfo structure and because we had not agreed to make the parse tree a read-only structure.

So, I=E2=80=99m fine with the changes in this patch.

--
regards, Andrei Lepikhov,
pgEdge


--000000000000dd4975064edbce0d--