Merge pull request #4215 from citusdata/fix/rls-moves

pull/4227/head
Marco Slot 2020-10-06 14:16:40 +02:00 committed by GitHub
commit f904ce1726
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 48 additions and 70 deletions

View File

@ -287,7 +287,7 @@ GetShellTableDDLEventsForCitusLocalTable(Oid relationId)
*/
bool includeSequenceDefaults = true;
List *shellTableDDLEvents = GetTableDDLEvents(relationId,
List *shellTableDDLEvents = GetFullTableCreationCommands(relationId,
includeSequenceDefaults);
shellTableDDLEvents = list_concat(shellTableDDLEvents, foreignConstraintCommands);

View File

@ -1576,7 +1576,7 @@ RelationUsesHeapAccessMethodOrNone(Relation relation)
*
* The undistributed table will have the same name, columns and rows. It will also have
* partitions, views, sequences of the old table. Finally it will have everything created
* by GetTableConstructionCommands function, which include indexes. These will be
* by GetPostLoadTableCreationCommands function, which include indexes. These will be
* re-created during undistribution, so their oids are not preserved either (except for
* sequences). However, their names are preserved.
*
@ -1618,10 +1618,10 @@ UndistributeTable(Oid relationId)
}
List *tableBuildingCommands = GetTableBuildingCommands(relationId, true);
List *tableConstructionCommands = GetTableConstructionCommands(relationId);
List *preLoadCommands = GetPreLoadTableCreationCommands(relationId, true);
List *postLoadCommands = GetPostLoadTableCreationCommands(relationId);
tableConstructionCommands = list_concat(tableConstructionCommands,
postLoadCommands = list_concat(postLoadCommands,
GetViewCreationCommandsOfTable(relationId));
int spiResult = SPI_connect();
@ -1655,7 +1655,7 @@ UndistributeTable(Oid relationId)
{
ereport(ERROR, (errmsg("could not run SPI query")));
}
tableBuildingCommands = lappend(tableBuildingCommands,
preLoadCommands = lappend(preLoadCommands,
attachPartitionCommand);
UndistributeTable(partitionRelationId);
}
@ -1670,7 +1670,7 @@ UndistributeTable(Oid relationId)
ereport(NOTICE, (errmsg("Creating a new local table for %s",
quote_qualified_identifier(schemaName, relationName))));
foreach_ptr(tableCreationCommand, tableBuildingCommands)
foreach_ptr(tableCreationCommand, preLoadCommands)
{
Node *parseTree = ParseTreeNode(tableCreationCommand);
@ -1682,7 +1682,7 @@ UndistributeTable(Oid relationId)
ReplaceTable(relationId, get_relname_relid(tempName, schemaId));
char *tableConstructionCommand = NULL;
foreach_ptr(tableConstructionCommand, tableConstructionCommands)
foreach_ptr(tableConstructionCommand, postLoadCommands)
{
spiResult = SPI_execute(tableConstructionCommand, false, 0);
if (spiResult != SPI_OK_UTILITY)

View File

@ -398,7 +398,8 @@ MetadataCreateCommands(void)
}
List *workerSequenceDDLCommands = SequenceDDLCommandsForTable(relationId);
List *ddlCommandList = GetTableDDLEvents(relationId, includeSequenceDefaults);
List *ddlCommandList = GetFullTableCreationCommands(relationId,
includeSequenceDefaults);
char *tableOwnerResetCommand = TableOwnerResetCommand(relationId);
List *sequenceDependencyCommandList = SequenceDependencyCommandList(relationId);
@ -510,13 +511,10 @@ GetDistributedTableDDLEvents(Oid relationId)
commandList = list_concat(commandList, sequenceDDLCommands);
/* commands to create the table */
List *tableDDLCommands = GetTableDDLEvents(relationId, includeSequenceDefaults);
List *tableDDLCommands = GetFullTableCreationCommands(relationId,
includeSequenceDefaults);
commandList = list_concat(commandList, tableDDLCommands);
/* command to reset the table owner */
char *tableOwnerResetCommand = TableOwnerResetCommand(relationId);
commandList = lappend(commandList, tableOwnerResetCommand);
/* command to associate sequences with table */
List *sequenceDependencyCommandList = SequenceDependencyCommandList(relationId);
commandList = list_concat(commandList, sequenceDependencyCommandList);

View File

@ -221,7 +221,8 @@ master_get_table_ddl_events(PG_FUNCTION_ARGS)
functionContext->multi_call_memory_ctx);
/* allocate DDL statements, and then save position in DDL statements */
List *tableDDLEventList = GetTableDDLEvents(relationId, includeSequenceDefaults);
List *tableDDLEventList = GetFullTableCreationCommands(relationId,
includeSequenceDefaults);
tableDDLEventCell = list_head(tableDDLEventList);
ListCellAndListWrapper *wrapper = palloc0(sizeof(ListCellAndListWrapper));
wrapper->list = tableDDLEventList;
@ -522,7 +523,7 @@ ResolveRelationId(text *relationName, bool missingOk)
/*
* GetTableDDLEvents takes in a relationId, includeSequenceDefaults flag,
* GetFullTableCreationCommands takes in a relationId, includeSequenceDefaults flag,
* and returns the list of DDL commands needed to reconstruct the relation.
* When the flag includeSequenceDefaults is set, the function also creates
* DEFAULT clauses for columns getting their default values from a sequence.
@ -531,28 +532,30 @@ ResolveRelationId(text *relationName, bool missingOk)
* constraint and trigger definitions.
*/
List *
GetTableDDLEvents(Oid relationId, bool includeSequenceDefaults)
GetFullTableCreationCommands(Oid relationId, bool includeSequenceDefaults)
{
List *tableDDLEventList = NIL;
List *tableCreationCommandList = GetTableCreationCommands(relationId,
includeSequenceDefaults);
tableDDLEventList = list_concat(tableDDLEventList, tableCreationCommandList);
List *preLoadCreationCommandList =
GetPreLoadTableCreationCommands(relationId, includeSequenceDefaults);
List *otherCommands = GetTableConstructionCommands(relationId);
tableDDLEventList = list_concat(tableDDLEventList, otherCommands);
tableDDLEventList = list_concat(tableDDLEventList, preLoadCreationCommandList);
List *postLoadCreationCommandList =
GetPostLoadTableCreationCommands(relationId);
tableDDLEventList = list_concat(tableDDLEventList, postLoadCreationCommandList);
return tableDDLEventList;
}
/*
* GetTableConstructionCommands takes in a relationId and returns the list
* of DDL commands needed to reconstruct the relation except the ones that actually
* create the table.
* GetPostLoadTableCreationCommands takes in a relationId and returns the list
* of DDL commands that should be applied after loading the data.
*/
List *
GetTableConstructionCommands(Oid relationId)
GetPostLoadTableCreationCommands(Oid relationId)
{
List *tableDDLEventList = NIL;
@ -562,9 +565,6 @@ GetTableConstructionCommands(Oid relationId)
List *replicaIdentityEvents = GetTableReplicaIdentityCommand(relationId);
tableDDLEventList = list_concat(tableDDLEventList, replicaIdentityEvents);
List *policyCommands = CreatePolicyCommands(relationId);
tableDDLEventList = list_concat(tableDDLEventList, policyCommands);
List *triggerCommands = GetExplicitTriggerCommandList(relationId);
tableDDLEventList = list_concat(tableDDLEventList, triggerCommands);
@ -604,12 +604,12 @@ GetTableReplicaIdentityCommand(Oid relationId)
/*
* GetTableCreationCommands takes in a relationId, and returns the list of DDL
* commands needed to reconstruct the relation, excluding indexes and
* constraints.
* GetPreLoadTableCreationCommands takes in a relationId, and returns the list of DDL
* commands needed to reconstruct the relation, excluding indexes and constraints,
* to facilitate faster data load.
*/
List *
GetTableCreationCommands(Oid relationId, bool includeSequenceDefaults)
GetPreLoadTableCreationCommands(Oid relationId, bool includeSequenceDefaults)
{
List *tableDDLEventList = NIL;
@ -629,30 +629,6 @@ GetTableCreationCommands(Oid relationId, bool includeSequenceDefaults)
tableDDLEventList = lappend(tableDDLEventList, serverDef);
}
List *tableBuildingCommands = GetTableBuildingCommands(relationId,
includeSequenceDefaults);
tableDDLEventList = list_concat(tableDDLEventList,
tableBuildingCommands);
/* revert back to original search_path */
PopOverrideSearchPath();
return tableDDLEventList;
}
/*
* GetTableBuildingCommands takes in a relationId, and returns the list of DDL
* commands needed to rebuild the relation. This does not include the schema
* and the server commands.
*/
List *
GetTableBuildingCommands(Oid relationId, bool includeSequenceDefaults)
{
List *tableDDLEventList = NIL;
PushOverrideEmptySearchPath(CurrentMemoryContext);
/* fetch table schema and column option definitions */
char *tableSchemaDef = pg_get_tableschemadef_string(relationId,
includeSequenceDefaults);
@ -670,6 +646,9 @@ GetTableBuildingCommands(Oid relationId, bool includeSequenceDefaults)
tableDDLEventList = lappend(tableDDLEventList, tableOwnerDef);
}
List *policyCommands = CreatePolicyCommands(relationId);
tableDDLEventList = list_concat(tableDDLEventList, policyCommands);
/* revert back to original search_path */
PopOverrideSearchPath();

View File

@ -775,7 +775,7 @@ CopyShardCommandList(ShardInterval *shardInterval, const char *sourceNodeName,
copyShardDataCommand->data);
}
List *indexCommandList = GetTableIndexAndConstraintCommands(relationId);
List *indexCommandList = GetPostLoadTableCreationCommands(relationId);
indexCommandList = WorkerApplyShardDDLCommandList(indexCommandList, shardId);
copyShardToNodeCommandsList = list_concat(copyShardToNodeCommandsList,
@ -980,7 +980,7 @@ RecreateTableDDLCommandList(Oid relationId)
}
List *dropCommandList = list_make1(dropCommand->data);
List *createCommandList = GetTableCreationCommands(relationId,
List *createCommandList = GetPreLoadTableCreationCommands(relationId,
includeSequenceDefaults);
List *recreateCommandList = list_concat(dropCommandList, createCommandList);

View File

@ -396,7 +396,8 @@ CreateAppendDistributedShardPlacements(Oid relationId, int64 shardId,
List *foreignConstraintCommandList =
GetReferencingForeignConstaintCommands(relationId);
bool includeSequenceDefaults = false;
List *ddlCommandList = GetTableDDLEvents(relationId, includeSequenceDefaults);
List *ddlCommandList = GetFullTableCreationCommands(relationId,
includeSequenceDefaults);
uint32 connectionFlag = FOR_DDL;
char *relationOwner = TableOwner(relationId);
@ -500,7 +501,7 @@ CreateShardsOnWorkers(Oid distributedRelationId, List *shardPlacements,
bool useExclusiveConnection, bool colocatedShard)
{
bool includeSequenceDefaults = false;
List *ddlCommandList = GetTableDDLEvents(distributedRelationId,
List *ddlCommandList = GetFullTableCreationCommands(distributedRelationId,
includeSequenceDefaults);
List *foreignConstraintCommandList =
GetReferencingForeignConstaintCommands(distributedRelationId);

View File

@ -100,10 +100,10 @@ extern bool CStoreTable(Oid relationId);
extern uint64 GetNextShardId(void);
extern uint64 GetNextPlacementId(void);
extern Oid ResolveRelationId(text *relationName, bool missingOk);
extern List * GetTableDDLEvents(Oid relationId, bool forShardCreation);
extern List * GetTableConstructionCommands(Oid relationId);
extern List * GetTableCreationCommands(Oid relationId, bool forShardCreation);
extern List * GetTableBuildingCommands(Oid relationId, bool includeSequenceDefaults);
extern List * GetFullTableCreationCommands(Oid relationId, bool includeSequenceDefaults);
extern List * GetPostLoadTableCreationCommands(Oid relationId);
extern List * GetPreLoadTableCreationCommands(Oid relationId,
bool includeSequenceDefaults);
extern List * GetTableIndexAndConstraintCommands(Oid relationId);
extern bool IndexImpliedByAConstraint(Form_pg_index indexForm);
extern char ShardStorageType(Oid relationId);