do not cascade DROP commands always

improve-drop-trigger2
Onur Tirtir 2020-03-10 01:30:36 +03:00
parent fd195b13b0
commit 2b8c56fd44
4 changed files with 23 additions and 2 deletions

View File

@ -70,6 +70,8 @@ static bool shouldInvalidateForeignKeyGraph = false;
static int activeAlterTables = 0;
static int activeDropSchemaOrDBs = 0;
/* assume always cascading for the direct usage of master_drop_all_shards */
bool isDropCommandCascading = true;
/* Local functions forward declarations for helper functions */
static void ExecuteDistributedDDLJob(DDLJob *ddlJob);
@ -455,6 +457,14 @@ multi_ProcessUtility(PlannedStmt *pstmt,
StopMaintenanceDaemon(MyDatabaseId);
}
if (IsA(parsetree, DropStmt))
{
DropStmt *dropStmt = castNode(DropStmt, parsetree);
/* to set DROP behaviors of the DROP shard commands accordingly */
isDropCommandCascading = (dropStmt->behavior == DROP_CASCADE);
}
pstmt->utilityStmt = parsetree;
PG_TRY();
@ -487,6 +497,9 @@ multi_ProcessUtility(PlannedStmt *pstmt,
standard_ProcessUtility(pstmt, queryString, context,
params, queryEnv, dest, completionTag);
/* assume always cascading for the direct usage of master_drop_all_shards */
isDropCommandCascading = true;
/*
* if we are running ALTER EXTENSION citus UPDATE (to "<version>") command, we may need
* to mark existing objects as distributed depending on the "version" parameter if

View File

@ -609,6 +609,11 @@ CreateDropShardPlacementCommand(const char *schemaName, const char *shardRelatio
Assert(false);
}
if (isDropCommandCascading)
{
appendStringInfo(workerDropQuery, " CASCADE");
}
return workerDropQuery->data;
}

View File

@ -32,6 +32,9 @@ extern bool EnableDependencyCreation;
extern bool EnableCreateTypePropagation;
extern bool EnableAlterRolePropagation;
/* whether current DROP command is cascading or not */
extern bool isDropCommandCascading;
/*
* A DDLJob encapsulates the remote tasks and commands needed to process all or
* part of a distributed DDL command. It hold the distributed relation's oid,

View File

@ -67,8 +67,8 @@
#define SHARD_RANGE_QUERY "SELECT min(%s), max(%s) FROM %s"
#define SHARD_TABLE_SIZE_QUERY "SELECT pg_table_size(%s)"
#define SHARD_CSTORE_TABLE_SIZE_QUERY "SELECT cstore_table_size(%s)"
#define DROP_REGULAR_TABLE_COMMAND "DROP TABLE IF EXISTS %s CASCADE"
#define DROP_FOREIGN_TABLE_COMMAND "DROP FOREIGN TABLE IF EXISTS %s CASCADE"
#define DROP_REGULAR_TABLE_COMMAND "DROP TABLE IF EXISTS %s"
#define DROP_FOREIGN_TABLE_COMMAND "DROP FOREIGN TABLE IF EXISTS %s"
#define CREATE_SCHEMA_COMMAND "CREATE SCHEMA IF NOT EXISTS %s AUTHORIZATION %s"
/* Enumeration that defines the shard placement policy to use while staging */