Miłosz Bieniek <[email protected]> 于2026年8月27日周四 18:21写道:
> I think `root` argument was introduced in [1] to do an assertion,
> but that assertion was removed shortly after being added.
> `from` and `to` on the other hand were introduced in [2],
> but weren't used from the start.
>
> LGTM!
>
> [1] 
> https://www.postgresql.org/message-id/CAKJS1f8cJOCGyoxi7a_LG7eu%2BWKF9%2BHTff3wp1KKS5gcUg2Qfg%40mail.gmail.com
> [2] 
> https://www.postgresql.org/message-id/c97574c4-13e6-9107-26ab-af2bd626fc85%40postgrespro.ru
>

Thanks, Miłosz, for the review and the historical details.

While looking through the SJE code again, I noticed that the "root"
argument of match_unique_clauses() is also unused. Attached is v2,
which removes that argument in addition to the three unused arguments
of split_selfjoin_quals() covered by the original patch.

There is no functional change.

-- 
Thanks,
Tender Wang
From c2faeb8128e212b919ff5fb2f8f7e036648e1a57 Mon Sep 17 00:00:00 2001
From: Tender Wang <[email protected]>
Date: Wed, 19 Aug 2026 14:35:38 +0800
Subject: [PATCH] Remove unused parameters from self-join elimination functions

Remove unused parameters from split_selfjoin_quals() and
match_unique_clauses(). These parameters have been unused since
self-join elimination was introduced.
---
 src/backend/optimizer/plan/analyzejoins.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/src/backend/optimizer/plan/analyzejoins.c 
b/src/backend/optimizer/plan/analyzejoins.c
index 7aad91fd34e..25a863efbde 100644
--- a/src/backend/optimizer/plan/analyzejoins.c
+++ b/src/backend/optimizer/plan/analyzejoins.c
@@ -1655,8 +1655,8 @@ replace_selfjoin_qual(Node *qual)
  * itself.
  */
 static void
-split_selfjoin_quals(PlannerInfo *root, List *joinquals, List **selfjoinquals,
-                                        List **otherjoinquals, int from, int 
to)
+split_selfjoin_quals(List *joinquals, List **selfjoinquals,
+                                        List **otherjoinquals)
 {
        List       *sjoinquals = NIL;
        List       *ojoinquals = NIL;
@@ -1727,8 +1727,7 @@ split_selfjoin_quals(PlannerInfo *root, List *joinquals, 
List **selfjoinquals,
  * a great deal of extra complication without much extra value.
  */
 static bool
-match_unique_clauses(PlannerInfo *root, RelOptInfo *outer, List *uclauses,
-                                        Index relid)
+match_unique_clauses(RelOptInfo *outer, List *uclauses, Index relid)
 {
        Assert(outer->relid > 0 && relid > 0);
 
@@ -1881,8 +1880,7 @@ remove_self_joins_one_group(PlannerInfo *root, Relids 
relids)
                         * other quals. e.g., "x = x" goes to selfjoinquals and 
"a = b" to
                         * otherjoinquals.
                         */
-                       split_selfjoin_quals(root, restrictlist, &selfjoinquals,
-                                                                
&otherjoinquals, rrel->relid, krel->relid);
+                       split_selfjoin_quals(restrictlist, &selfjoinquals, 
&otherjoinquals);
 
                        Assert(list_length(restrictlist) ==
                                   (list_length(selfjoinquals) + 
list_length(otherjoinquals)));
@@ -1919,7 +1917,7 @@ remove_self_joins_one_group(PlannerInfo *root, Relids 
relids)
                         * expressions, or we won't match the same row on each 
side of the
                         * join.
                         */
-                       if (!match_unique_clauses(root, rrel, uclauses, 
krel->relid))
+                       if (!match_unique_clauses(rrel, uclauses, krel->relid))
                                continue;
 
                        /* OK, remove rrel from the query */
-- 
2.43.0

Reply via email to