From 49812ddfa066885bda4eecf42d92b57c19dd1a1c Mon Sep 17 00:00:00 2001 From: Burak Velioglu Date: Mon, 20 Feb 2017 17:08:44 +0300 Subject: [PATCH] Disallow master_apply_delete_command on hash distributed table Delete operation is blocked for any table distributed by hash using master_apply_delete_command. Suggested master_modify_multiple_shards command as a hint. --- .../distributed/master/master_delete_protocol.c | 8 +++++--- src/test/regress/expected/multi_utilities.out | 13 ++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/backend/distributed/master/master_delete_protocol.c b/src/backend/distributed/master/master_delete_protocol.c index b46852886..0d3525d84 100644 --- a/src/backend/distributed/master/master_delete_protocol.c +++ b/src/backend/distributed/master/master_delete_protocol.c @@ -145,12 +145,14 @@ master_apply_delete_command(PG_FUNCTION_ARGS) deleteCriteria = eval_const_expressions(NULL, whereClause); partitionMethod = PartitionMethod(relationId); - if ((partitionMethod == DISTRIBUTE_BY_HASH) && (deleteCriteria != NULL)) + if (partitionMethod == DISTRIBUTE_BY_HASH) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("cannot delete from distributed table"), + errmsg("cannot delete from hash distributed table with this " + "command"), errdetail("Delete statements on hash-partitioned tables " - "with where clause is not supported"))); + "are not supported with master_apply_delete_command."), + errhint("Use master_modify_multiple_shards command instead."))); } else if (partitionMethod == DISTRIBUTE_BY_NONE) { diff --git a/src/test/regress/expected/multi_utilities.out b/src/test/regress/expected/multi_utilities.out index 737017745..eda3b3a87 100644 --- a/src/test/regress/expected/multi_utilities.out +++ b/src/test/regress/expected/multi_utilities.out @@ -55,15 +55,14 @@ EXECUTE sharded_query; -- try to drop shards with where clause SELECT master_apply_delete_command('DELETE FROM sharded_table WHERE id > 0'); -ERROR: cannot delete from distributed table -DETAIL: Delete statements on hash-partitioned tables with where clause is not supported +ERROR: cannot delete from hash distributed table with this command +DETAIL: Delete statements on hash-partitioned tables are not supported with master_apply_delete_command. +HINT: Use master_modify_multiple_shards command instead. -- drop all shards SELECT master_apply_delete_command('DELETE FROM sharded_table'); - master_apply_delete_command ------------------------------ - 2 -(1 row) - +ERROR: cannot delete from hash distributed table with this command +DETAIL: Delete statements on hash-partitioned tables are not supported with master_apply_delete_command. +HINT: Use master_modify_multiple_shards command instead. -- lock shard metadata: take some share locks and exclusive locks BEGIN; SELECT lock_shard_metadata(5, ARRAY[999001, 999002, 999002]);