From 15b62979e21f13dc337a86c363e457e53e8bafd2 Mon Sep 17 00:00:00 2001 From: aykutbozkurt Date: Tue, 9 May 2023 22:20:59 +0300 Subject: [PATCH] we should consider all kinds of tables as colocated if their relation ids are same --- .../relation_restriction_equivalence.c | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/backend/distributed/planner/relation_restriction_equivalence.c b/src/backend/distributed/planner/relation_restriction_equivalence.c index ac36842de..3c1f050c2 100644 --- a/src/backend/distributed/planner/relation_restriction_equivalence.c +++ b/src/backend/distributed/planner/relation_restriction_equivalence.c @@ -171,6 +171,7 @@ static bool FindQueryContainingRTEIdentityInternal(Node *node, static int ParentCountPriorToAppendRel(List *appendRelList, AppendRelInfo *appendRelInfo); +static bool AllRelationsSame(List *relationList); /* * AllDistributionKeysInQueryAreEqual returns true if either @@ -1960,6 +1961,31 @@ AllDistributedRelationsInRTEListColocated(List *rangeTableEntryList) } +/* + * AllRelationsSame determines whether all of the relations are the same. + */ +static bool +AllRelationsSame(List *relationList) +{ + if (relationList == NULL || list_length(relationList) == 0) + { + return true; + } + + Oid firstRelationId = linitial_oid(relationList); + Oid relationId = InvalidOid; + foreach_oid(relationId, relationList) + { + if (relationId != firstRelationId) + { + return false; + } + } + + return true; +} + + /* * AllDistributedRelationsInListColocated determines whether all of the * distributed relations in the given list are co-located. @@ -1967,6 +1993,11 @@ AllDistributedRelationsInRTEListColocated(List *rangeTableEntryList) bool AllDistributedRelationsInListColocated(List *relationList) { + if (AllRelationsSame(relationList)) + { + return true; + } + int initialColocationId = INVALID_COLOCATION_ID; Oid relationId = InvalidOid;