Support dropping local table indexes along with a distributed index

pull/4714/head
Ahmet Gedemenli 2021-02-15 17:35:34 +03:00
parent 676d9a9726
commit 1f345f65b4
3 changed files with 27 additions and 28 deletions

View File

@ -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.

View File

@ -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

View File

@ -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;