From 05b4711962d7999d918d10d6b50605c857fddce6 Mon Sep 17 00:00:00 2001 From: Burak Velioglu Date: Thu, 20 Jan 2022 01:47:37 +0300 Subject: [PATCH] Use function to get inter table relation --- .../distributed/metadata/metadata_sync.c | 42 ++++++++++++------- .../distributed/metadata/node_metadata.c | 37 ++++------------ 2 files changed, 35 insertions(+), 44 deletions(-) diff --git a/src/backend/distributed/metadata/metadata_sync.c b/src/backend/distributed/metadata/metadata_sync.c index 9947d6435..7c5ad2645 100644 --- a/src/backend/distributed/metadata/metadata_sync.c +++ b/src/backend/distributed/metadata/metadata_sync.c @@ -1851,7 +1851,7 @@ HasMetadataWorkers(void) /* * CreateInterTableRelationshipOfRelationOnWorkers create inter table relationship - * for the the given relation id. + * for the the given relation id on each worker node with metadata. */ void CreateInterTableRelationshipOfRelationOnWorkers(Oid relationId) @@ -1863,20 +1863,8 @@ CreateInterTableRelationshipOfRelationOnWorkers(Oid relationId) return; } - List *commandList = NIL; - - /* commands to create foreign key constraints */ - List *foreignConstraintCommands = - GetReferencingForeignConstaintCommands(relationId); - commandList = list_concat(commandList, foreignConstraintCommands); - - /* commands to create partitioning hierarchy */ - if (PartitionTable(relationId)) - { - char *alterTableAttachPartitionCommands = - GenerateAlterTableAttachPartitionCommand(relationId); - commandList = lappend(commandList, alterTableAttachPartitionCommands); - } + List *commandList = + InterTableRelationshipOfRelationCommandList(relationId); /* prevent recursive propagation */ SendCommandToWorkersWithMetadata(DISABLE_DDL_PROPAGATION); @@ -1889,6 +1877,30 @@ CreateInterTableRelationshipOfRelationOnWorkers(Oid relationId) } +/* + * InterTableRelationshipOfRelationCommandList returns the command list to create + * inter table relationship for the given relation. + */ +List * +InterTableRelationshipOfRelationCommandList(Oid relationId) +{ + /* commands to create foreign key constraints */ + List *foreignConstraintCommands = + GetReferencingForeignConstaintCommands(relationId); + List *commandList = list_concat(commandList, foreignConstraintCommands); + + /* commands to create partitioning hierarchy */ + if (PartitionTable(relationId)) + { + char *alterTableAttachPartitionCommands = + GenerateAlterTableAttachPartitionCommand(relationId); + commandList = lappend(commandList, alterTableAttachPartitionCommands); + } + + return commandList; +} + + /* * CreateShellTableOnWorkers creates the shell table on each worker node with metadata * including sequence dependency and truncate triggers. diff --git a/src/backend/distributed/metadata/node_metadata.c b/src/backend/distributed/metadata/node_metadata.c index 7621047a3..b0d9936e7 100644 --- a/src/backend/distributed/metadata/node_metadata.c +++ b/src/backend/distributed/metadata/node_metadata.c @@ -111,7 +111,7 @@ static List * MetadataSetupCommandList(); static List * ClearMetadataCommandList(); static List * ClearShellTablesCommandList(); static void SetUpDistributedTableWithDependencies(WorkerNode *workerNode); -static List * MultipleDistributedTableIntegrationsCommandList(); +static List * InterTableRelationshipCommandList(); static WorkerNode * TupleToWorkerNode(TupleDesc tupleDescriptor, HeapTuple heapTuple); static List * PropagateNodeWideObjectsCommandList(); static WorkerNode * ModifiableWorkerNode(const char *nodeName, int32 nodePort); @@ -579,15 +579,16 @@ master_set_node_property(PG_FUNCTION_ARGS) /* - * MultipleDistributedTableIntegrationsCommandList returns the command list to + * InterTableRelationshipCommandList returns the command list to * set up the multiple integrations including * * (i) Foreign keys * (ii) Partionining hierarchy * + * for each citus table. */ static List * -MultipleDistributedTableIntegrationsCommandList() +InterTableRelationshipCommandList() { List *distributedTableList = CitusTableList(); List *propagatedTableList = NIL; @@ -613,34 +614,12 @@ MultipleDistributedTableIntegrationsCommandList() continue; } - List *foreignConstraintCommands = - GetReferencingForeignConstaintCommands(relationId); + List *commandListForRelation = + InterTableRelationshipOfRelationCommandList(relationId); multipleTableIntegrationCommandList = list_concat( multipleTableIntegrationCommandList, - foreignConstraintCommands); - } - - /* construct partitioning hierarchy after all tables are created */ - foreach_ptr(cacheEntry, propagatedTableList) - { - Oid relationId = cacheEntry->relationId; - - if (IsTableOwnedByExtension(relationId)) - { - /* skip partition creation when the Citus table is owned by an extension */ - continue; - } - - if (PartitionTable(relationId)) - { - char *alterTableAttachPartitionCommands = - GenerateAlterTableAttachPartitionCommand(relationId); - - multipleTableIntegrationCommandList = lappend( - multipleTableIntegrationCommandList, - alterTableAttachPartitionCommands); - } + commandListForRelation); } multipleTableIntegrationCommandList = lcons(DISABLE_DDL_PROPAGATION, @@ -790,7 +769,7 @@ RecreateDistributedTablesWithDependenciesCommandList(WorkerNode *workerNode) workerNode->workerName, workerNode->workerPort)); commandList = list_concat(commandList, - MultipleDistributedTableIntegrationsCommandList()); + InterTableRelationshipCommandList()); return commandList; }