diff --git a/src/backend/distributed/commands/index.c b/src/backend/distributed/commands/index.c index f77a0f6f2..415ef5419 100644 --- a/src/backend/distributed/commands/index.c +++ b/src/backend/distributed/commands/index.c @@ -73,7 +73,6 @@ 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); @@ -696,9 +695,21 @@ 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; } } @@ -706,8 +717,6 @@ PreprocessDropIndexStmt(Node *node, const char *dropIndexCommand, { DDLJob *ddlJob = palloc0(sizeof(DDLJob)); - ErrorIfUnsupportedDropIndexStmt(dropIndexStatement); - if (AnyForeignKeyDependsOnIndex(distributedIndexId)) { MarkInvalidateForeignKeyGraph(); @@ -1170,26 +1179,6 @@ 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. diff --git a/src/test/regress/expected/multi_index_statements.out b/src/test/regress/expected/multi_index_statements.out index fae7550e1..137e69484 100644 --- a/src/test/regress/expected/multi_index_statements.out +++ b/src/test/regress/expected/multi_index_statements.out @@ -222,11 +222,16 @@ 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 diff --git a/src/test/regress/sql/multi_index_statements.sql b/src/test/regress/sql/multi_index_statements.sql index 66ef7a685..fd3fc5667 100644 --- a/src/test/regress/sql/multi_index_statements.sql +++ b/src/test/regress/sql/multi_index_statements.sql @@ -137,12 +137,17 @@ 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;