mirror of https://github.com/citusdata/citus.git
Move truncate trigger
parent
bee36628a1
commit
368e4dbb74
|
@ -658,10 +658,10 @@ GetShellTableDDLEventsForCitusLocalTable(Oid relationId)
|
|||
*/
|
||||
IncludeSequenceDefaults includeSequenceDefaults = NEXTVAL_SEQUENCE_DEFAULTS;
|
||||
|
||||
bool associateSequenceDependency = false;
|
||||
bool creatingShellTableOnRemoteNode = false;
|
||||
List *tableDDLCommands = GetFullTableCreationCommands(relationId,
|
||||
includeSequenceDefaults,
|
||||
associateSequenceDependency);
|
||||
creatingShellTableOnRemoteNode);
|
||||
|
||||
List *shellTableDDLEvents = NIL;
|
||||
TableDDLCommand *tableDDLCommand = NULL;
|
||||
|
|
|
@ -243,15 +243,16 @@ GetDependencyCreateDDLCommands(const ObjectAddress *dependency)
|
|||
|
||||
if (IsCitusTable(relationId))
|
||||
{
|
||||
bool associateSequenceDependency = true;
|
||||
bool creatingShellTableOnRemoteNode = true;
|
||||
List *tableDDLCommands = GetFullTableCreationCommands(relationId,
|
||||
WORKER_NEXTVAL_SEQUENCE_DEFAULTS,
|
||||
associateSequenceDependency);
|
||||
creatingShellTableOnRemoteNode);
|
||||
TableDDLCommand *tableDDLCommand = NULL;
|
||||
foreach_ptr(tableDDLCommand, tableDDLCommands)
|
||||
{
|
||||
Assert(CitusIsA(tableDDLCommand, TableDDLCommand));
|
||||
commandList = lappend(commandList, GetTableDDLCommand(tableDDLCommand));
|
||||
commandList = lappend(commandList, GetTableDDLCommand(
|
||||
tableDDLCommand));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1574,7 +1574,8 @@ SequenceDependencyCommandList(Oid relationId)
|
|||
CreateSequenceDependencyCommand(relationId, sequenceId, columnName);
|
||||
|
||||
sequenceCommandList = lappend(sequenceCommandList,
|
||||
makeTableDDLCommandString(sequenceDependencyCommand));
|
||||
makeTableDDLCommandString(
|
||||
sequenceDependencyCommand));
|
||||
}
|
||||
|
||||
return sequenceCommandList;
|
||||
|
@ -1805,7 +1806,7 @@ GenerateSetRoleQuery(Oid roleOid)
|
|||
* TruncateTriggerCreateCommand creates a SQL query calling worker_create_truncate_trigger
|
||||
* function, which creates the truncate trigger on the worker.
|
||||
*/
|
||||
char *
|
||||
TableDDLCommand *
|
||||
TruncateTriggerCreateCommand(Oid relationId)
|
||||
{
|
||||
StringInfo triggerCreateCommand = makeStringInfo();
|
||||
|
@ -1815,7 +1816,10 @@ TruncateTriggerCreateCommand(Oid relationId)
|
|||
"SELECT worker_create_truncate_trigger(%s)",
|
||||
quote_literal_cstr(tableName));
|
||||
|
||||
return triggerCreateCommand->data;
|
||||
TableDDLCommand *triggerDDLCommand = makeTableDDLCommandString(
|
||||
triggerCreateCommand->data);
|
||||
|
||||
return triggerDDLCommand;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1937,10 +1941,10 @@ CreateShellTableOnWorkers(Oid relationId)
|
|||
IncludeSequenceDefaults includeSequenceDefaults =
|
||||
WORKER_NEXTVAL_SEQUENCE_DEFAULTS;
|
||||
|
||||
bool associateSequenceDependency = true;
|
||||
bool creatingShellTableOnRemoteNode = true;
|
||||
List *tableDDLCommands = GetFullTableCreationCommands(relationId,
|
||||
includeSequenceDefaults,
|
||||
associateSequenceDependency);
|
||||
creatingShellTableOnRemoteNode);
|
||||
TableDDLCommand *tableDDLCommand = NULL;
|
||||
foreach_ptr(tableDDLCommand, tableDDLCommands)
|
||||
{
|
||||
|
@ -1949,12 +1953,6 @@ CreateShellTableOnWorkers(Oid relationId)
|
|||
}
|
||||
}
|
||||
|
||||
if (!IsForeignTable(relationId))
|
||||
{
|
||||
char *truncateTriggerCreateCommand = TruncateTriggerCreateCommand(relationId);
|
||||
commandList = lappend(commandList, truncateTriggerCreateCommand);
|
||||
}
|
||||
|
||||
/* prevent recursive propagation */
|
||||
SendCommandToWorkersWithMetadata(DISABLE_DDL_PROPAGATION);
|
||||
|
||||
|
|
|
@ -668,15 +668,6 @@ PgDistTableMetadataSyncCommandList(void)
|
|||
metadataSnapshotCommandList = lappend(metadataSnapshotCommandList,
|
||||
metadataCommand);
|
||||
|
||||
/* add the truncate trigger command after the table became distributed */
|
||||
if (!IsForeignTable(clusteredTableId))
|
||||
{
|
||||
char *truncateTriggerCreateCommand =
|
||||
TruncateTriggerCreateCommand(clusteredTableId);
|
||||
metadataSnapshotCommandList = lappend(metadataSnapshotCommandList,
|
||||
truncateTriggerCreateCommand);
|
||||
}
|
||||
|
||||
/* add the pg_dist_shard{,placement} entries */
|
||||
List *shardIntervalList = LoadShardIntervalList(clusteredTableId);
|
||||
List *shardCreateCommandList = ShardListInsertCommand(shardIntervalList);
|
||||
|
|
|
@ -141,10 +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;
|
||||
bool creatingShellTableOnRemoteNode = false;
|
||||
List *tableDDLEventList = GetFullTableCreationCommands(relationId,
|
||||
includeSequenceDefaults,
|
||||
associateSequenceDependency);
|
||||
creatingShellTableOnRemoteNode);
|
||||
tableDDLEventCell = list_head(tableDDLEventList);
|
||||
ListCellAndListWrapper *wrapper = palloc0(sizeof(ListCellAndListWrapper));
|
||||
wrapper->list = tableDDLEventList;
|
||||
|
@ -462,7 +462,7 @@ ResolveRelationId(text *relationName, bool missingOk)
|
|||
List *
|
||||
GetFullTableCreationCommands(Oid relationId,
|
||||
IncludeSequenceDefaults includeSequenceDefaults,
|
||||
bool associateSequenceDependency)
|
||||
bool creatingShellTableOnRemoteNode)
|
||||
{
|
||||
List *tableDDLEventList = NIL;
|
||||
|
||||
|
@ -474,14 +474,23 @@ GetFullTableCreationCommands(Oid relationId,
|
|||
List *postLoadCreationCommandList =
|
||||
GetPostLoadTableCreationCommands(relationId, true, true);
|
||||
|
||||
if (associateSequenceDependency)
|
||||
if (creatingShellTableOnRemoteNode)
|
||||
{
|
||||
/*
|
||||
* While creating shell tables, we need to associate dependencies between
|
||||
* sequences and the relation.
|
||||
* sequences and the relation. We also need to add truncate trigger for it
|
||||
* if it is not the foreign table.
|
||||
*/
|
||||
List *sequenceDependencyCommandList = SequenceDependencyCommandList(relationId);
|
||||
tableDDLEventList = list_concat(tableDDLEventList, sequenceDependencyCommandList);
|
||||
|
||||
if (!IsForeignTable(relationId))
|
||||
{
|
||||
TableDDLCommand *truncateTriggerCommand = TruncateTriggerCreateCommand(
|
||||
relationId);
|
||||
tableDDLEventList = lappend(tableDDLEventList,
|
||||
truncateTriggerCommand);
|
||||
}
|
||||
}
|
||||
|
||||
tableDDLEventList = list_concat(tableDDLEventList, postLoadCreationCommandList);
|
||||
|
|
|
@ -325,10 +325,10 @@ CreateAppendDistributedShardPlacements(Oid relationId, int64 shardId,
|
|||
List *foreignConstraintCommandList =
|
||||
GetReferencingForeignConstaintCommands(relationId);
|
||||
IncludeSequenceDefaults includeSequenceDefaults = NO_SEQUENCE_DEFAULTS;
|
||||
bool associateSequenceDependency = false;
|
||||
bool creatingShellTableOnRemoteNode = false;
|
||||
List *ddlCommandList = GetFullTableCreationCommands(relationId,
|
||||
includeSequenceDefaults,
|
||||
associateSequenceDependency);
|
||||
creatingShellTableOnRemoteNode);
|
||||
uint32 connectionFlag = FOR_DDL;
|
||||
char *relationOwner = TableOwner(relationId);
|
||||
|
||||
|
@ -440,10 +440,10 @@ CreateShardsOnWorkers(Oid distributedRelationId, List *shardPlacements,
|
|||
bool useExclusiveConnection, bool colocatedShard)
|
||||
{
|
||||
IncludeSequenceDefaults includeSequenceDefaults = NO_SEQUENCE_DEFAULTS;
|
||||
bool associateSequenceDependency = false;
|
||||
bool creatingShellTableOnRemoteNode = false;
|
||||
List *ddlCommandList = GetFullTableCreationCommands(distributedRelationId,
|
||||
includeSequenceDefaults,
|
||||
associateSequenceDependency);
|
||||
creatingShellTableOnRemoteNode);
|
||||
List *foreignConstraintCommandList =
|
||||
GetReferencingForeignConstaintCommands(distributedRelationId);
|
||||
|
||||
|
|
|
@ -225,7 +225,7 @@ extern uint64 GetNextPlacementId(void);
|
|||
extern Oid ResolveRelationId(text *relationName, bool missingOk);
|
||||
extern List * GetFullTableCreationCommands(Oid relationId,
|
||||
IncludeSequenceDefaults includeSequenceDefaults,
|
||||
bool associateSequenceDependency);
|
||||
bool creatingShellTableOnRemoteNode);
|
||||
extern List * GetPostLoadTableCreationCommands(Oid relationId, bool includeIndexes,
|
||||
bool includeReplicaIdentity);
|
||||
extern List * GetPreLoadTableCreationCommands(Oid relationId, IncludeSequenceDefaults
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#define METADATA_SYNC_H
|
||||
|
||||
|
||||
#include "distributed/coordinator_protocol.h"
|
||||
#include "distributed/metadata_cache.h"
|
||||
#include "nodes/pg_list.h"
|
||||
|
||||
|
@ -55,7 +56,7 @@ extern char * CreateSchemaDDLCommand(Oid schemaId);
|
|||
extern List * GrantOnSchemaDDLCommands(Oid schemaId);
|
||||
extern char * PlacementUpsertCommand(uint64 shardId, uint64 placementId, int shardState,
|
||||
uint64 shardLength, int32 groupId);
|
||||
extern char * TruncateTriggerCreateCommand(Oid relationId);
|
||||
extern TableDDLCommand * TruncateTriggerCreateCommand(Oid relationId);
|
||||
extern void CreateInterTableRelationshipOfRelationOnWorkers(Oid relationId);
|
||||
extern List * InterTableRelationshipOfRelationCommandList(Oid relationId);
|
||||
extern void CreateShellTableOnWorkers(Oid relationId);
|
||||
|
|
Loading…
Reference in New Issue