diff --git a/src/backend/distributed/metadata/metadata_sync.c b/src/backend/distributed/metadata/metadata_sync.c index 7c5ad2645..4ac378ff1 100644 --- a/src/backend/distributed/metadata/metadata_sync.c +++ b/src/backend/distributed/metadata/metadata_sync.c @@ -1885,9 +1885,7 @@ List * InterTableRelationshipOfRelationCommandList(Oid relationId) { /* commands to create foreign key constraints */ - List *foreignConstraintCommands = - GetReferencingForeignConstaintCommands(relationId); - List *commandList = list_concat(commandList, foreignConstraintCommands); + List *commandList = GetReferencingForeignConstaintCommands(relationId); /* commands to create partitioning hierarchy */ if (PartitionTable(relationId)) diff --git a/src/backend/distributed/metadata/node_metadata.c b/src/backend/distributed/metadata/node_metadata.c index b0d9936e7..d1555357b 100644 --- a/src/backend/distributed/metadata/node_metadata.c +++ b/src/backend/distributed/metadata/node_metadata.c @@ -597,23 +597,21 @@ InterTableRelationshipCommandList() CitusTableCacheEntry *cacheEntry = NULL; foreach_ptr(cacheEntry, distributedTableList) { - if (ShouldSyncTableMetadata(cacheEntry->relationId)) + /* + * Skip foreign key and partition creation when we shouldn't need to sync + * tablem metadata or the Citus table is owned by an extension. + */ + if (ShouldSyncTableMetadata(cacheEntry->relationId) && + !IsTableOwnedByExtension(cacheEntry->relationId)) { propagatedTableList = lappend(propagatedTableList, cacheEntry); } } - /* construct the foreign key constraints after all tables are created */ foreach_ptr(cacheEntry, propagatedTableList) { Oid relationId = cacheEntry->relationId; - if (IsTableOwnedByExtension(relationId)) - { - /* skip foreign key creation when the Citus table is owned by an extension */ - continue; - } - List *commandListForRelation = InterTableRelationshipOfRelationCommandList(relationId); diff --git a/src/include/distributed/metadata_sync.h b/src/include/distributed/metadata_sync.h index 96d8a0533..a2ed97777 100644 --- a/src/include/distributed/metadata_sync.h +++ b/src/include/distributed/metadata_sync.h @@ -56,6 +56,7 @@ extern char * PlacementUpsertCommand(uint64 shardId, uint64 placementId, int sha uint64 shardLength, int32 groupId); extern char * TruncateTriggerCreateCommand(Oid relationId); extern void CreateInterTableRelationshipOfRelationOnWorkers(Oid relationId); +extern List * InterTableRelationshipOfRelationCommandList(Oid relationId); extern void CreateShellTableOnWorkers(Oid relationId); extern void CreateTableMetadataOnWorkers(Oid relationId); extern List * DetachPartitionCommandList(void);