From c6f5cabbe335d7de9668f3341bebc01e74250061 Mon Sep 17 00:00:00 2001 From: Metin Doslu Date: Wed, 26 Oct 2016 18:39:53 +0300 Subject: [PATCH] Error on different shard placement count In ErrorIfShardPlacementsNotColocated(), while checking if shards are colocated, error out if matching shard intervals have different number of shard placements. --- src/backend/distributed/utils/colocation_utils.c | 15 +++++++++++++-- .../regress/expected/multi_colocation_utils.out | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/backend/distributed/utils/colocation_utils.c b/src/backend/distributed/utils/colocation_utils.c index 11060526f..432fedd27 100644 --- a/src/backend/distributed/utils/colocation_utils.c +++ b/src/backend/distributed/utils/colocation_utils.c @@ -151,8 +151,9 @@ MarkTablesColocated(Oid sourceRelationId, Oid targetRelationId) * following cases: * 1.Shard counts are different, * 2.Shard intervals don't match - * 3.Shard placements are not colocated (not on the same node) - * 4.Shard placements have different health states + * 3.Matching shard intervals have different number of shard placements + * 4.Shard placements are not colocated (not on the same node) + * 5.Shard placements have different health states * * Note that, this functions assumes that both tables are hash distributed. */ @@ -219,6 +220,16 @@ ErrorIfShardPlacementsNotColocated(Oid leftRelationId, Oid rightRelationId) leftPlacementList = ShardPlacementList(leftShardId); rightPlacementList = ShardPlacementList(rightShardId); + if (list_length(leftPlacementList) != list_length(rightPlacementList)) + { + ereport(ERROR, (errmsg("cannot colocate tables %s and %s", + leftRelationName, rightRelationName), + errdetail("Shard %ld of %s and shard %ld of %s " + "have different number of shard placements.", + leftShardId, leftRelationName, + rightShardId, rightRelationName))); + } + /* sort shard placements according to the node */ sortedLeftPlacementList = SortList(leftPlacementList, CompareShardPlacementsByNode); diff --git a/src/test/regress/expected/multi_colocation_utils.out b/src/test/regress/expected/multi_colocation_utils.out index b87eba729..7bd235aeb 100644 --- a/src/test/regress/expected/multi_colocation_utils.out +++ b/src/test/regress/expected/multi_colocation_utils.out @@ -689,7 +689,7 @@ ERROR: cannot colocate tables table1_groupb and table1_groupd DETAIL: Shard counts don't match for table1_groupb and table1_groupd. SELECT mark_tables_colocated('table1_groupB', ARRAY['table1_groupE']); ERROR: cannot colocate tables table1_groupb and table1_groupe -DETAIL: Shard 1300027 of table1_groupb and shard 1300047 of table1_groupe are not colocated. +DETAIL: Shard 1300026 of table1_groupb and shard 1300046 of table1_groupe have different number of shard placements. SELECT mark_tables_colocated('table1_groupB', ARRAY['table1_groupF']); ERROR: cannot colocate tables table1_groupb and table1_groupf DETAIL: Shard counts don't match for table1_groupb and table1_groupf.