mirror of https://github.com/citusdata/citus.git
Use GetFullTableCreationCommands
parent
ccea041d6a
commit
bee36628a1
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue