Skip to content

Commit

Permalink
Fixes create index concurrently bug
Browse files Browse the repository at this point in the history
(cherry picked from commit 38b72dd)
  • Loading branch information
halilozanakgul committed Jul 27, 2020
1 parent 39e63f5 commit 993a402
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
12 changes: 11 additions & 1 deletion src/backend/distributed/commands/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,24 @@ 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();

/* 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 */
Expand Down
7 changes: 4 additions & 3 deletions src/test/regress/expected/multi_index_statements.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/test/regress/sql/multi_index_statements.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 993a402

Please sign in to comment.