diff --git a/src/backend/distributed/master/master_stage_protocol.c b/src/backend/distributed/master/master_stage_protocol.c index f6dbabaf1..f34cd5e1e 100644 --- a/src/backend/distributed/master/master_stage_protocol.c +++ b/src/backend/distributed/master/master_stage_protocol.c @@ -728,11 +728,15 @@ RelationShardListForShardCreate(ShardInterval *shardInterval) DistTableCacheEntry *cacheEntry = DistributedTableCacheEntry(relationId); List *referencedRelationList = cacheEntry->referencedRelationsViaForeignKey; List *referencingRelationList = cacheEntry->referencingRelationsViaForeignKey; - List *allForeignKeyRelations = - list_concat_unique_oid(referencedRelationList, referencingRelationList); + List *allForeignKeyRelations = NIL; int shardIndex = -1; ListCell *fkeyRelationIdCell = NULL; + /* list_concat_*() modifies the first arg, so make a copy first */ + allForeignKeyRelations = list_copy(referencedRelationList); + allForeignKeyRelations = list_concat_unique_oid(allForeignKeyRelations, + referencingRelationList); + /* record the placement access of the shard itself */ relationShard = CitusMakeNode(RelationShard); relationShard->relationId = relationId;