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
* 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.

View File

@ -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;
}