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