From 914aa87c4eb6f1a27818deb8190ce36c1a0bd4f8 Mon Sep 17 00:00:00 2001 From: Hanefi Onaldi Date: Mon, 8 May 2023 18:03:20 +0300 Subject: [PATCH] Do not acquire locks if the index does not exist --- src/backend/distributed/commands/index.c | 20 +++++++++---------- .../expected/isolation_drop_vs_all.out | 3 ++- .../expected/isolation_multiuser_locking.out | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/backend/distributed/commands/index.c b/src/backend/distributed/commands/index.c index 1d7dbb448..4edb319f7 100644 --- a/src/backend/distributed/commands/index.c +++ b/src/backend/distributed/commands/index.c @@ -748,16 +748,6 @@ PreprocessDropIndexStmt(Node *node, const char *dropIndexCommand, lockmode = ShareUpdateExclusiveLock; } - /* - * Acquire global lock to prevent concurrent writes or DDL. However, - * we do not bother for DROP INDEX CONCURRENTLY, since we'll have - * to release the lock. - */ - if (!dropIndexStatement->concurrent) - { - AcquireDistributedLockOnRelations(list_make1(rangeVar), lockmode, 0); - } - /* * The next few statements are based on RemoveRelations() in * commands/tablecmds.c in Postgres source. @@ -781,6 +771,16 @@ PreprocessDropIndexStmt(Node *node, const char *dropIndexCommand, continue; } + /* + * Acquire global lock to prevent concurrent writes or DDL. However, + * we do not bother for DROP INDEX CONCURRENTLY, since we'll have + * to release the lock. + */ + if (!dropIndexStatement->concurrent) + { + AcquireDistributedLockOnRelations(list_make1(rangeVar), lockmode, 0); + } + Oid relationId = IndexGetRelation(indexId, false); bool isCitusRelation = IsCitusTable(relationId); if (isCitusRelation) diff --git a/src/test/regress/expected/isolation_drop_vs_all.out b/src/test/regress/expected/isolation_drop_vs_all.out index 7dab13615..a061fa9ba 100644 --- a/src/test/regress/expected/isolation_drop_vs_all.out +++ b/src/test/regress/expected/isolation_drop_vs_all.out @@ -68,8 +68,9 @@ step s2-begin: BEGIN; step s1-drop: DROP TABLE drop_hash; step s2-ddl-create-index: CREATE INDEX drop_hash_index ON drop_hash(id); step s1-commit: COMMIT; +s2: WARNING: relation "drop_tests.drop_hash" does not exist step s2-ddl-create-index: <... completed> -ERROR: relation "drop_hash" does not exist +ERROR: failure on connection marked as essential: localhost:xxxxx step s2-commit: COMMIT; step s1-select-count: SELECT COUNT(*) FROM drop_hash; ERROR: relation "drop_hash" does not exist diff --git a/src/test/regress/expected/isolation_multiuser_locking.out b/src/test/regress/expected/isolation_multiuser_locking.out index 943d579a4..996fb6c9d 100644 --- a/src/test/regress/expected/isolation_multiuser_locking.out +++ b/src/test/regress/expected/isolation_multiuser_locking.out @@ -140,7 +140,7 @@ step s2-begin: step s2-index: CREATE INDEX test_index ON test_table(column1); -ERROR: must be owner of table test_table +ERROR: permission denied for table test_table step s1-insert: UPDATE test_table SET column2 = 1;