Fix drop index trying to drop coordinator local indexes on metadata worker nodes

pull/5525/head
Halil Ozan Akgul 2021-12-13 13:57:54 +03:00
parent 811eda6d0f
commit a951e52ce8
4 changed files with 30 additions and 28 deletions

View File

@ -24,6 +24,7 @@
#include "distributed/commands.h"
#include "distributed/commands/utility_hook.h"
#include "distributed/deparse_shard_query.h"
#include "distributed/deparser.h"
#include "distributed/distributed_planner.h"
#include "distributed/listutils.h"
#include "distributed/local_executor.h"
@ -71,6 +72,7 @@ static void RangeVarCallbackForReindexIndex(const RangeVar *rel, Oid relOid, Oid
oldRelOid,
void *arg);
static void ErrorIfUnsupportedIndexStmt(IndexStmt *createIndexStatement);
static void ErrorIfUnsupportedDropIndexStmt(DropStmt *dropIndexStatement);
static List * DropIndexTaskList(Oid relationId, Oid indexId, DropStmt *dropStmt);
@ -676,21 +678,9 @@ PreprocessDropIndexStmt(Node *node, const char *dropIndexCommand,
bool isCitusRelation = IsCitusTable(relationId);
if (isCitusRelation)
{
if (OidIsValid(distributedIndexId))
{
/*
* We already have a distributed index in the list, and Citus
* currently only support dropping a single distributed index.
*/
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot drop multiple distributed objects in "
"a single command"),
errhint("Try dropping each object in a separate DROP "
"command.")));
}
distributedIndexId = indexId;
distributedRelationId = relationId;
break;
}
}
@ -698,6 +688,8 @@ PreprocessDropIndexStmt(Node *node, const char *dropIndexCommand,
{
DDLJob *ddlJob = palloc0(sizeof(DDLJob));
ErrorIfUnsupportedDropIndexStmt(dropIndexStatement);
if (AnyForeignKeyDependsOnIndex(distributedIndexId))
{
MarkInvalidateForeignKeyGraph();
@ -1159,6 +1151,26 @@ ErrorIfUnsupportedIndexStmt(IndexStmt *createIndexStatement)
}
/*
* ErrorIfUnsupportedDropIndexStmt checks if the corresponding drop index statement is
* supported for distributed tables and errors out if it is not.
*/
static void
ErrorIfUnsupportedDropIndexStmt(DropStmt *dropIndexStatement)
{
Assert(dropIndexStatement->removeType == OBJECT_INDEX);
if (list_length(dropIndexStatement->objects) > 1)
{
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot drop multiple distributed objects in a "
"single command"),
errhint("Try dropping each object in a separate DROP "
"command.")));
}
}
/*
* DropIndexTaskList builds a list of tasks to execute a DROP INDEX command
* against a specified distributed table.

View File

@ -255,16 +255,11 @@ DROP INDEX lineitem_orderkey_index, lineitem_partial_index;
ERROR: cannot drop multiple distributed objects in a single command
HINT: Try dropping each object in a separate DROP command.
-- Verify that we can succesfully drop indexes
DROP INDEX lineitem_orderkey_index;
DROP INDEX lineitem_orderkey_index_new;
DROP INDEX lineitem_partkey_desc_index;
DROP INDEX lineitem_partial_index;
DROP INDEX lineitem_colref_index;
-- Verify that we can drop distributed indexes with local indexes
CREATE TABLE local_table(a int, b int);
CREATE INDEX local_index ON local_table(a);
CREATE INDEX local_index2 ON local_table(b);
DROP INDEX lineitem_orderkey_index, local_index;
DROP INDEX IF EXISTS lineitem_orderkey_index_new, local_index2, non_existing_index;
NOTICE: index "non_existing_index" does not exist, skipping
-- Verify that we handle if exists statements correctly
DROP INDEX non_existent_index;
ERROR: index "non_existent_index" does not exist

View File

@ -150,6 +150,7 @@ test: with_executors with_join with_partitioning with_transactions with_dml
# ----------
# Tests around DDL statements run on distributed tables
# ----------
test: multi_index_statements
test: multi_alter_table_statements
test: multi_alter_table_add_constraints
@ -193,7 +194,6 @@ test: multi_repartition_udt multi_repartitioned_subquery_udf multi_subtransactio
test: multi_modifying_xacts
test: check_mx
test: turn_mx_off
test: multi_index_statements
test: multi_generate_ddl_commands multi_repair_shards
test: multi_create_shards
test: multi_transaction_recovery

View File

@ -159,17 +159,12 @@ REINDEX SYSTEM regression;
DROP INDEX lineitem_orderkey_index, lineitem_partial_index;
-- Verify that we can succesfully drop indexes
DROP INDEX lineitem_orderkey_index;
DROP INDEX lineitem_orderkey_index_new;
DROP INDEX lineitem_partkey_desc_index;
DROP INDEX lineitem_partial_index;
DROP INDEX lineitem_colref_index;
-- Verify that we can drop distributed indexes with local indexes
CREATE TABLE local_table(a int, b int);
CREATE INDEX local_index ON local_table(a);
CREATE INDEX local_index2 ON local_table(b);
DROP INDEX lineitem_orderkey_index, local_index;
DROP INDEX IF EXISTS lineitem_orderkey_index_new, local_index2, non_existing_index;
-- Verify that we handle if exists statements correctly
DROP INDEX non_existent_index;