diff --git a/src/backend/distributed/executor/multi_utility.c b/src/backend/distributed/executor/multi_utility.c index c6fca17b5..564c91251 100644 --- a/src/backend/distributed/executor/multi_utility.c +++ b/src/backend/distributed/executor/multi_utility.c @@ -572,6 +572,25 @@ ProcessAlterTableStmt(AlterTableStmt *alterTableStatement, const char *alterTabl static void ErrorIfUnsupportedIndexStmt(IndexStmt *createIndexStatement) { + Oid namespaceId; + Oid indexRelationId; + char* indexRelationName = createIndexStatement->idxname; + + if (indexRelationName == NULL) + { + ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("creating index without a name on a distributed table is " + "currently unsupported"))); + } + + namespaceId = get_namespace_oid(createIndexStatement->relation->schemaname, false); + indexRelationId = get_relname_relid(indexRelationName, namespaceId); + if (indexRelationId != InvalidOid) + { + ereport(ERROR, (errcode(ERRCODE_DUPLICATE_TABLE), + errmsg("relation \"%s\" already exists", indexRelationName))); + } + if (createIndexStatement->tableSpace != NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), diff --git a/src/test/regress/expected/multi_index_statements.out b/src/test/regress/expected/multi_index_statements.out index 73e834e50..d6f903a94 100644 --- a/src/test/regress/expected/multi_index_statements.out +++ b/src/test/regress/expected/multi_index_statements.out @@ -135,9 +135,7 @@ ERROR: creating unique indexes on append-partitioned tables is currently unsupp -- Verify that we error out in case of postgres errors on supported statement -- types. CREATE INDEX lineitem_orderkey_index ON lineitem (l_orderkey); -WARNING: could not receive query results from localhost:57638 -DETAIL: Client error: relation "lineitem_orderkey_index_102014" already exists -ERROR: could not execute DDL command on worker node shards +ERROR: relation "lineitem_orderkey_index" already exists CREATE INDEX try_index ON lineitem USING gist (l_orderkey); WARNING: could not receive query results from localhost:57638 DETAIL: Client error: data type bigint has no default operator class for access method "gist" @@ -146,6 +144,8 @@ CREATE INDEX try_index ON lineitem (non_existent_column); WARNING: could not receive query results from localhost:57638 DETAIL: Client error: column "non_existent_column" does not exist ERROR: could not execute DDL command on worker node shards +CREATE INDEX ON lineitem (l_orderkey); +ERROR: creating index without a name on a distributed table is currently unsupported -- Verify that none of failed indexes got created on the master node SELECT * FROM pg_indexes WHERE tablename = 'lineitem' or tablename like 'index_test_%' ORDER BY indexname; schemaname | tablename | indexname | tablespace | indexdef diff --git a/src/test/regress/sql/multi_index_statements.sql b/src/test/regress/sql/multi_index_statements.sql index 942680da6..66be10f63 100644 --- a/src/test/regress/sql/multi_index_statements.sql +++ b/src/test/regress/sql/multi_index_statements.sql @@ -73,6 +73,7 @@ CREATE UNIQUE INDEX try_unique_append_index_a_b ON index_test_append(a,b); CREATE INDEX lineitem_orderkey_index ON lineitem (l_orderkey); CREATE INDEX try_index ON lineitem USING gist (l_orderkey); CREATE INDEX try_index ON lineitem (non_existent_column); +CREATE INDEX ON lineitem (l_orderkey); -- Verify that none of failed indexes got created on the master node SELECT * FROM pg_indexes WHERE tablename = 'lineitem' or tablename like 'index_test_%' ORDER BY indexname;