From ed77260aa183d9acb6dd0cbc676753b64b1f2547 Mon Sep 17 00:00:00 2001 From: Metin Doslu Date: Thu, 19 Jan 2017 17:11:44 +0200 Subject: [PATCH] Return a deep copy shard list from ColocatedShardIntervalList() --- src/backend/distributed/utils/colocation_utils.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/backend/distributed/utils/colocation_utils.c b/src/backend/distributed/utils/colocation_utils.c index 6df607a89..f2af93772 100644 --- a/src/backend/distributed/utils/colocation_utils.c +++ b/src/backend/distributed/utils/colocation_utils.c @@ -841,7 +841,11 @@ ColocatedShardIntervalList(ShardInterval *shardInterval) if ((partitionMethod == DISTRIBUTE_BY_APPEND) || (partitionMethod == DISTRIBUTE_BY_RANGE)) { - colocatedShardList = lappend(colocatedShardList, shardInterval); + ShardInterval *copyShardInterval = CitusMakeNode(ShardInterval); + CopyShardInterval(shardInterval, copyShardInterval); + + colocatedShardList = lappend(colocatedShardList, copyShardInterval); + return colocatedShardList; } @@ -857,6 +861,7 @@ ColocatedShardIntervalList(ShardInterval *shardInterval) DistTableCacheEntry *colocatedTableCacheEntry = DistributedTableCacheEntry(colocatedTableId); ShardInterval *colocatedShardInterval = NULL; + ShardInterval *copyShardInterval = NULL; /* * Since we iterate over co-located tables, shard count of each table should be @@ -868,7 +873,10 @@ ColocatedShardIntervalList(ShardInterval *shardInterval) colocatedShardInterval = colocatedTableCacheEntry->sortedShardIntervalArray[shardIntervalIndex]; - colocatedShardList = lappend(colocatedShardList, colocatedShardInterval); + copyShardInterval = CitusMakeNode(ShardInterval); + CopyShardInterval(colocatedShardInterval, copyShardInterval); + + colocatedShardList = lappend(colocatedShardList, copyShardInterval); } Assert(list_length(colocatedTableList) == list_length(colocatedShardList));