diff --git a/src/backend/distributed/commands/index.c b/src/backend/distributed/commands/index.c index 57d96645d..d7af058c9 100644 --- a/src/backend/distributed/commands/index.c +++ b/src/backend/distributed/commands/index.c @@ -411,6 +411,16 @@ PostprocessIndexStmt(Node *node, const char *queryString) return NIL; } + /* + * We make sure schema name is not null in the PreprocessIndexStmt + */ + Oid schemaId = get_namespace_oid(indexStmt->relation->schemaname, true); + Oid relationId = get_relname_relid(indexStmt->relation->relname, schemaId); + if (!IsCitusTable(relationId)) + { + return NIL; + } + /* commit the current transaction and start anew */ CommitTransactionCommand(); StartTransactionCommand(); @@ -418,7 +428,7 @@ PostprocessIndexStmt(Node *node, const char *queryString) /* get the affected relation and index */ Relation relation = heap_openrv(indexStmt->relation, ShareUpdateExclusiveLock); Oid indexRelationId = get_relname_relid(indexStmt->idxname, - RelationGetNamespace(relation)); + schemaId); Relation indexRelation = index_open(indexRelationId, RowExclusiveLock); /* close relations but retain locks */ diff --git a/src/test/regress/expected/multi_index_statements.out b/src/test/regress/expected/multi_index_statements.out index 7d3515336..4d76402a3 100644 --- a/src/test/regress/expected/multi_index_statements.out +++ b/src/test/regress/expected/multi_index_statements.out @@ -86,15 +86,16 @@ CREATE INDEX IF NOT EXISTS lineitem_orderkey_index on index_test_hash(a); NOTICE: relation "lineitem_orderkey_index" already exists, skipping -- Verify that we can create indexes concurrently CREATE INDEX CONCURRENTLY lineitem_concurrently_index ON lineitem (l_orderkey); +-- Verify that no-name local CREATE INDEX CONCURRENTLY works +CREATE TABLE local_table (id integer, name text); +CREATE INDEX CONCURRENTLY ON local_table(id); -- Verify that we warn out on CLUSTER command for distributed tables and no parameter CLUSTER index_test_hash USING index_test_hash_index_a; WARNING: not propagating CLUSTER command to worker nodes CLUSTER; WARNING: not propagating CLUSTER command to worker nodes --- Verify that no-name local CREATE INDEX CONCURRENTLY works -CREATE TABLE local_table (id integer, name text); -CREATE INDEX CONCURRENTLY local_table_index ON local_table(id); -- Vefify we don't warn out on CLUSTER command for local tables +CREATE INDEX CONCURRENTLY local_table_index ON local_table(id); CLUSTER local_table USING local_table_index; DROP TABLE local_table; -- Verify that all indexes got created on the master node and one of the workers diff --git a/src/test/regress/sql/multi_index_statements.sql b/src/test/regress/sql/multi_index_statements.sql index e90e595f3..727482d49 100644 --- a/src/test/regress/sql/multi_index_statements.sql +++ b/src/test/regress/sql/multi_index_statements.sql @@ -64,15 +64,16 @@ CREATE INDEX IF NOT EXISTS lineitem_orderkey_index on index_test_hash(a); -- Verify that we can create indexes concurrently CREATE INDEX CONCURRENTLY lineitem_concurrently_index ON lineitem (l_orderkey); +-- Verify that no-name local CREATE INDEX CONCURRENTLY works +CREATE TABLE local_table (id integer, name text); +CREATE INDEX CONCURRENTLY ON local_table(id); + -- Verify that we warn out on CLUSTER command for distributed tables and no parameter CLUSTER index_test_hash USING index_test_hash_index_a; CLUSTER; --- Verify that no-name local CREATE INDEX CONCURRENTLY works -CREATE TABLE local_table (id integer, name text); -CREATE INDEX CONCURRENTLY local_table_index ON local_table(id); - -- Vefify we don't warn out on CLUSTER command for local tables +CREATE INDEX CONCURRENTLY local_table_index ON local_table(id); CLUSTER local_table USING local_table_index; DROP TABLE local_table;