From 5c157a5357b6b16de26eeac499cdd1d0632208a4 Mon Sep 17 00:00:00 2001 From: Halil Ozan Akgul Date: Thu, 23 Jul 2020 13:48:52 +0300 Subject: [PATCH] Fixes create index concurrently bug (cherry picked from commit 38b72ddd662dffeb55807ce361d0d8f16965029d) Changed IsCitusTable to IsDistributedTable --- src/backend/distributed/commands/index.c | 12 +++++++++++- src/test/regress/expected/multi_index_statements.out | 7 ++++--- src/test/regress/sql/multi_index_statements.sql | 9 +++++---- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/backend/distributed/commands/index.c b/src/backend/distributed/commands/index.c index 0fc43afa8..9823350b6 100644 --- a/src/backend/distributed/commands/index.c +++ b/src/backend/distributed/commands/index.c @@ -410,6 +410,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 (!IsDistributedTable(relationId)) + { + return NIL; + } + /* commit the current transaction and start anew */ CommitTransactionCommand(); StartTransactionCommand(); @@ -417,7 +427,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;