Use function to get inter table relation

velioglu/wo_seq_test_1
Burak Velioglu 2022-01-20 01:47:37 +03:00
parent c08220594f
commit 05b4711962
No known key found for this signature in database
GPG Key ID: F6827E620F6549C6
2 changed files with 35 additions and 44 deletions

View File

@ -1851,7 +1851,7 @@ HasMetadataWorkers(void)
/* /*
* CreateInterTableRelationshipOfRelationOnWorkers create inter table relationship * CreateInterTableRelationshipOfRelationOnWorkers create inter table relationship
* for the the given relation id. * for the the given relation id on each worker node with metadata.
*/ */
void void
CreateInterTableRelationshipOfRelationOnWorkers(Oid relationId) CreateInterTableRelationshipOfRelationOnWorkers(Oid relationId)
@ -1863,20 +1863,8 @@ CreateInterTableRelationshipOfRelationOnWorkers(Oid relationId)
return; return;
} }
List *commandList = NIL; List *commandList =
InterTableRelationshipOfRelationCommandList(relationId);
/* 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);
}
/* prevent recursive propagation */ /* prevent recursive propagation */
SendCommandToWorkersWithMetadata(DISABLE_DDL_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 * CreateShellTableOnWorkers creates the shell table on each worker node with metadata
* including sequence dependency and truncate triggers. * including sequence dependency and truncate triggers.

View File

@ -111,7 +111,7 @@ static List * MetadataSetupCommandList();
static List * ClearMetadataCommandList(); static List * ClearMetadataCommandList();
static List * ClearShellTablesCommandList(); static List * ClearShellTablesCommandList();
static void SetUpDistributedTableWithDependencies(WorkerNode *workerNode); static void SetUpDistributedTableWithDependencies(WorkerNode *workerNode);
static List * MultipleDistributedTableIntegrationsCommandList(); static List * InterTableRelationshipCommandList();
static WorkerNode * TupleToWorkerNode(TupleDesc tupleDescriptor, HeapTuple heapTuple); static WorkerNode * TupleToWorkerNode(TupleDesc tupleDescriptor, HeapTuple heapTuple);
static List * PropagateNodeWideObjectsCommandList(); static List * PropagateNodeWideObjectsCommandList();
static WorkerNode * ModifiableWorkerNode(const char *nodeName, int32 nodePort); 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 * set up the multiple integrations including
* *
* (i) Foreign keys * (i) Foreign keys
* (ii) Partionining hierarchy * (ii) Partionining hierarchy
* *
* for each citus table.
*/ */
static List * static List *
MultipleDistributedTableIntegrationsCommandList() InterTableRelationshipCommandList()
{ {
List *distributedTableList = CitusTableList(); List *distributedTableList = CitusTableList();
List *propagatedTableList = NIL; List *propagatedTableList = NIL;
@ -613,34 +614,12 @@ MultipleDistributedTableIntegrationsCommandList()
continue; continue;
} }
List *foreignConstraintCommands = List *commandListForRelation =
GetReferencingForeignConstaintCommands(relationId); InterTableRelationshipOfRelationCommandList(relationId);
multipleTableIntegrationCommandList = list_concat( multipleTableIntegrationCommandList = list_concat(
multipleTableIntegrationCommandList, multipleTableIntegrationCommandList,
foreignConstraintCommands); commandListForRelation);
}
/* 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);
}
} }
multipleTableIntegrationCommandList = lcons(DISABLE_DDL_PROPAGATION, multipleTableIntegrationCommandList = lcons(DISABLE_DDL_PROPAGATION,
@ -790,7 +769,7 @@ RecreateDistributedTablesWithDependenciesCommandList(WorkerNode *workerNode)
workerNode->workerName, workerNode->workerName,
workerNode->workerPort)); workerNode->workerPort));
commandList = list_concat(commandList, commandList = list_concat(commandList,
MultipleDistributedTableIntegrationsCommandList()); InterTableRelationshipCommandList());
return commandList; return commandList;
} }