From 2b8c56fd44f1a1c68c25ed2845bc763637050164 Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Tue, 10 Mar 2020 01:30:36 +0300 Subject: [PATCH] do not cascade DROP commands always --- src/backend/distributed/commands/utility_hook.c | 13 +++++++++++++ .../distributed/master/master_delete_protocol.c | 5 +++++ src/include/distributed/commands/utility_hook.h | 3 +++ src/include/distributed/master_protocol.h | 4 ++-- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/backend/distributed/commands/utility_hook.c b/src/backend/distributed/commands/utility_hook.c index 976f24cb7..f6a2942cd 100644 --- a/src/backend/distributed/commands/utility_hook.c +++ b/src/backend/distributed/commands/utility_hook.c @@ -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 "") command, we may need * to mark existing objects as distributed depending on the "version" parameter if diff --git a/src/backend/distributed/master/master_delete_protocol.c b/src/backend/distributed/master/master_delete_protocol.c index 397e1459e..8eef17c46 100644 --- a/src/backend/distributed/master/master_delete_protocol.c +++ b/src/backend/distributed/master/master_delete_protocol.c @@ -609,6 +609,11 @@ CreateDropShardPlacementCommand(const char *schemaName, const char *shardRelatio Assert(false); } + if (isDropCommandCascading) + { + appendStringInfo(workerDropQuery, " CASCADE"); + } + return workerDropQuery->data; } diff --git a/src/include/distributed/commands/utility_hook.h b/src/include/distributed/commands/utility_hook.h index 2dbf8d243..e07cc58d3 100644 --- a/src/include/distributed/commands/utility_hook.h +++ b/src/include/distributed/commands/utility_hook.h @@ -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, diff --git a/src/include/distributed/master_protocol.h b/src/include/distributed/master_protocol.h index b9f5b2671..4a5bdc73a 100644 --- a/src/include/distributed/master_protocol.h +++ b/src/include/distributed/master_protocol.h @@ -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 */