v5-0002-refactor-comments-in-remove_self_joins_one_group.patch
text/x-patch
Filename: v5-0002-refactor-comments-in-remove_self_joins_one_group.patch
Type: text/x-patch
Part: 0
Message:
Re: Removing unneeded self joins
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v5-0002
Subject: refactor comments in remove_self_joins_one_group
| File | + | − |
|---|---|---|
| src/backend/optimizer/plan/analyzejoins.c | 7 | 3 |
From a3b12e6b76205de7063298bf28e12e0ead8879cf Mon Sep 17 00:00:00 2001
From: jian he <jian.universality@gmail.com>
Date: Thu, 11 Jul 2024 15:11:28 +0800
Subject: [PATCH v5 2/2] refactor comments in remove_self_joins_one_group
---
src/backend/optimizer/plan/analyzejoins.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/backend/optimizer/plan/analyzejoins.c b/src/backend/optimizer/plan/analyzejoins.c
index 27bca772..1b9d66dd 100644
--- a/src/backend/optimizer/plan/analyzejoins.c
+++ b/src/backend/optimizer/plan/analyzejoins.c
@@ -2096,9 +2096,13 @@ remove_self_joins_one_group(PlannerInfo *root, Relids relids)
continue;
/*
- * We have proven that for both relations, the same unique index
- * guarantees that there is at most one row where columns equal
- * given values. These values must be the same for both relations,
+ * uclauses is the copy of outer->baserestrictinfo that associated with a index.
+ * We already proven that based on {outer->baserestrictinfo, selfjoinquals}
+ * comparsion with unique index we can guarantees that for the outer rel there is
+ * at most one row where columns equal given values. Sometimes that is not ok. e.g.
+ * "where s1.b = s2.b and s1.a = 1 and s2.a = 2". (the index is based on column(a,b).
+ * in these scarenio, we also need to validate equality of outer->baserestrictinfo
+ * with inner->outer->baserestrictinfo,
* or else we won't match the same row on each side of the join.
*/
if (!match_unique_clauses(root, inner, uclauses, outer->relid))
--
2.34.1