Use GetFullTableCreationCommands

velioglu/wo_seq_test_1
Burak Velioglu 2022-01-22 22:47:53 +03:00
parent ccea041d6a
commit bee36628a1
No known key found for this signature in database
GPG Key ID: F6827E620F6549C6
8 changed files with 45 additions and 46 deletions

View File

@ -658,8 +658,10 @@ GetShellTableDDLEventsForCitusLocalTable(Oid relationId)
*/
IncludeSequenceDefaults includeSequenceDefaults = NEXTVAL_SEQUENCE_DEFAULTS;
bool associateSequenceDependency = false;
List *tableDDLCommands = GetFullTableCreationCommands(relationId,
includeSequenceDefaults);
includeSequenceDefaults,
associateSequenceDependency);
List *shellTableDDLEvents = NIL;
TableDDLCommand *tableDDLCommand = NULL;

View File

@ -31,7 +31,6 @@ typedef bool (*AddressPredicate)(const ObjectAddress *);
static int ObjectAddressComparator(const void *a, const void *b);
static List * GetDependencyCreateDDLCommands(const ObjectAddress *dependency);
static List * GetCitusTableDDLCommandList(Oid relationId);
static List * FilterObjectAddressListByPredicate(List *objectAddressList,
AddressPredicate predicate);
@ -244,7 +243,16 @@ GetDependencyCreateDDLCommands(const ObjectAddress *dependency)
if (IsCitusTable(relationId))
{
commandList = GetCitusTableDDLCommandList(relationId);
bool associateSequenceDependency = true;
List *tableDDLCommands = GetFullTableCreationCommands(relationId,
WORKER_NEXTVAL_SEQUENCE_DEFAULTS,
associateSequenceDependency);
TableDDLCommand *tableDDLCommand = NULL;
foreach_ptr(tableDDLCommand, tableDDLCommands)
{
Assert(CitusIsA(tableDDLCommand, TableDDLCommand));
commandList = lappend(commandList, GetTableDDLCommand(tableDDLCommand));
}
}
return commandList;
@ -338,34 +346,6 @@ GetDependencyCreateDDLCommands(const ObjectAddress *dependency)
}
/*
* GetCitusTableDDLCommandList returns the list of commands to create citus table
* including the commands to associate sequences with table.
*/
static List *
GetCitusTableDDLCommandList(Oid relationId)
{
List *commandList = NIL;
List *tableDDLCommands = GetFullTableCreationCommands(relationId,
WORKER_NEXTVAL_SEQUENCE_DEFAULTS);
TableDDLCommand *tableDDLCommand = NULL;
foreach_ptr(tableDDLCommand, tableDDLCommands)
{
Assert(CitusIsA(tableDDLCommand, TableDDLCommand));
commandList = lappend(commandList, GetTableDDLCommand(tableDDLCommand));
}
/*
* Get commands to associate sequences with dependencies
*/
List *sequenceDependencyCommandList = SequenceDependencyCommandList(relationId);
commandList = list_concat(commandList, sequenceDependencyCommandList);
return commandList;
}
/*
* ReplicateAllObjectsToNodeCommandList returns commands to replicate all
* previously marked objects to a worker node. The function also sets

View File

@ -1574,7 +1574,7 @@ SequenceDependencyCommandList(Oid relationId)
CreateSequenceDependencyCommand(relationId, sequenceId, columnName);
sequenceCommandList = lappend(sequenceCommandList,
sequenceDependencyCommand);
makeTableDDLCommandString(sequenceDependencyCommand));
}
return sequenceCommandList;
@ -1937,18 +1937,16 @@ CreateShellTableOnWorkers(Oid relationId)
IncludeSequenceDefaults includeSequenceDefaults =
WORKER_NEXTVAL_SEQUENCE_DEFAULTS;
bool associateSequenceDependency = true;
List *tableDDLCommands = GetFullTableCreationCommands(relationId,
includeSequenceDefaults);
includeSequenceDefaults,
associateSequenceDependency);
TableDDLCommand *tableDDLCommand = NULL;
foreach_ptr(tableDDLCommand, tableDDLCommands)
{
Assert(CitusIsA(tableDDLCommand, TableDDLCommand));
commandList = lappend(commandList, GetTableDDLCommand(tableDDLCommand));
}
/* command to associate sequences with table */
List *sequenceDependencyCommandList = SequenceDependencyCommandList(relationId);
commandList = list_concat(commandList, sequenceDependencyCommandList);
}
if (!IsForeignTable(relationId))

View File

@ -141,8 +141,10 @@ master_get_table_ddl_events(PG_FUNCTION_ARGS)
functionContext->multi_call_memory_ctx);
/* allocate DDL statements, and then save position in DDL statements */
bool associateSequenceDependency = false;
List *tableDDLEventList = GetFullTableCreationCommands(relationId,
includeSequenceDefaults);
includeSequenceDefaults,
associateSequenceDependency);
tableDDLEventCell = list_head(tableDDLEventList);
ListCellAndListWrapper *wrapper = palloc0(sizeof(ListCellAndListWrapper));
wrapper->list = tableDDLEventList;
@ -458,8 +460,9 @@ ResolveRelationId(text *relationName, bool missingOk)
* constraint and trigger definitions.
*/
List *
GetFullTableCreationCommands(Oid relationId, IncludeSequenceDefaults
includeSequenceDefaults)
GetFullTableCreationCommands(Oid relationId,
IncludeSequenceDefaults includeSequenceDefaults,
bool associateSequenceDependency)
{
List *tableDDLEventList = NIL;
@ -471,6 +474,16 @@ GetFullTableCreationCommands(Oid relationId, IncludeSequenceDefaults
List *postLoadCreationCommandList =
GetPostLoadTableCreationCommands(relationId, true, true);
if (associateSequenceDependency)
{
/*
* While creating shell tables, we need to associate dependencies between
* sequences and the relation.
*/
List *sequenceDependencyCommandList = SequenceDependencyCommandList(relationId);
tableDDLEventList = list_concat(tableDDLEventList, sequenceDependencyCommandList);
}
tableDDLEventList = list_concat(tableDDLEventList, postLoadCreationCommandList);
return tableDDLEventList;

View File

@ -325,8 +325,10 @@ CreateAppendDistributedShardPlacements(Oid relationId, int64 shardId,
List *foreignConstraintCommandList =
GetReferencingForeignConstaintCommands(relationId);
IncludeSequenceDefaults includeSequenceDefaults = NO_SEQUENCE_DEFAULTS;
bool associateSequenceDependency = false;
List *ddlCommandList = GetFullTableCreationCommands(relationId,
includeSequenceDefaults);
includeSequenceDefaults,
associateSequenceDependency);
uint32 connectionFlag = FOR_DDL;
char *relationOwner = TableOwner(relationId);
@ -438,8 +440,10 @@ CreateShardsOnWorkers(Oid distributedRelationId, List *shardPlacements,
bool useExclusiveConnection, bool colocatedShard)
{
IncludeSequenceDefaults includeSequenceDefaults = NO_SEQUENCE_DEFAULTS;
bool associateSequenceDependency = false;
List *ddlCommandList = GetFullTableCreationCommands(distributedRelationId,
includeSequenceDefaults);
includeSequenceDefaults,
associateSequenceDependency);
List *foreignConstraintCommandList =
GetReferencingForeignConstaintCommands(distributedRelationId);

View File

@ -59,7 +59,8 @@ activate_node_snapshot(PG_FUNCTION_ARGS)
int activateNodeCommandIndex = 0;
Oid ddlCommandTypeId = TEXTOID;
activateNodeCommandList = list_concat(activateNodeCommandList, updateLocalGroupCommand);
activateNodeCommandList = list_concat(activateNodeCommandList,
updateLocalGroupCommand);
activateNodeCommandList = list_concat(activateNodeCommandList, syncObjectDepCommands);
activateNodeCommandList = list_concat(activateNodeCommandList, dropSnapshotCommands);
activateNodeCommandList = list_concat(activateNodeCommandList,

View File

@ -181,7 +181,7 @@ worker_drop_shell_table(PG_FUNCTION_ARGS)
if (IsObjectAddressOwnedByExtension(&distributedTableObject, NULL))
{
PG_RETURN_VOID();;
PG_RETURN_VOID();
}
/* Drop dependent sequences from pg_dist_object */

View File

@ -224,7 +224,8 @@ extern uint64 GetNextShardId(void);
extern uint64 GetNextPlacementId(void);
extern Oid ResolveRelationId(text *relationName, bool missingOk);
extern List * GetFullTableCreationCommands(Oid relationId,
IncludeSequenceDefaults includeSequenceDefaults);
IncludeSequenceDefaults includeSequenceDefaults,
bool associateSequenceDependency);
extern List * GetPostLoadTableCreationCommands(Oid relationId, bool includeIndexes,
bool includeReplicaIdentity);
extern List * GetPreLoadTableCreationCommands(Oid relationId, IncludeSequenceDefaults