diff --git a/src/backend/commands/resgroupcmds.c b/src/backend/commands/resgroupcmds.c index 384675edb7f..b152e25fc3f 100644 --- a/src/backend/commands/resgroupcmds.c +++ b/src/backend/commands/resgroupcmds.c @@ -34,6 +34,7 @@ #include "commands/resgroupcmds.h" #include "miscadmin.h" #include "nodes/pg_list.h" +#include "storage/proc.h" #include "utils/builtins.h" #include "utils/datetime.h" #include "utils/fmgroids.h" @@ -716,10 +717,17 @@ GetResGroupIdForRole(Oid roleid) HeapTuple tuple; Oid groupId; bool isNull; + bool releaseSnapshot; Relation rel; ScanKeyData key; SysScanDesc sscan; + /* + * StartTransaction() might hold a catalog snapshot with a valid xmin. + * As this fails the "CREATE INDEX CONCURRENTLY" status checks, explicitly + * release the snapshot. + */ + releaseSnapshot = MyProc->xmin == InvalidTransactionId; rel = table_open(AuthIdRelationId, AccessShareLock); ScanKeyInit(&key, @@ -757,6 +765,9 @@ GetResGroupIdForRole(Oid roleid) */ table_close(rel, AccessShareLock); + if (releaseSnapshot) + InvalidateCatalogSnapshot(); + if (!OidIsValid(groupId)) groupId = InvalidOid; diff --git a/src/test/isolation2/expected/resgroup/resgroup_transaction.out b/src/test/isolation2/expected/resgroup/resgroup_transaction.out index baad66ef535..a302f77236f 100644 --- a/src/test/isolation2/expected/resgroup/resgroup_transaction.out +++ b/src/test/isolation2/expected/resgroup/resgroup_transaction.out @@ -237,3 +237,16 @@ DROP -- cleanup DROP VIEW rg_test_monitor; DROP + +-- ---------------------------------------------------------------------- +-- Test: "CREATE INDEX CONCURRENTLY" when compiled with enable-cassert +-- ---------------------------------------------------------------------- + +CREATE TABLE t(a text, b text); +CREATE +CREATE INDEX CONCURRENTLY t_idx ON t(a, b); +CREATE +DROP INDEX CONCURRENTLY t_idx; +DROP +DROP TABLE t; +DROP diff --git a/src/test/isolation2/sql/resgroup/resgroup_transaction.sql b/src/test/isolation2/sql/resgroup/resgroup_transaction.sql index da29d48f208..7ab6f40b33b 100644 --- a/src/test/isolation2/sql/resgroup/resgroup_transaction.sql +++ b/src/test/isolation2/sql/resgroup/resgroup_transaction.sql @@ -134,3 +134,12 @@ DROP FUNCTION rg_drop_func(); -- cleanup DROP VIEW rg_test_monitor; + +-- ---------------------------------------------------------------------- +-- Test: "CREATE INDEX CONCURRENTLY" when compiled with enable-cassert +-- ---------------------------------------------------------------------- + +CREATE TABLE t(a text, b text); +CREATE INDEX CONCURRENTLY t_idx ON t(a, b); +DROP INDEX CONCURRENTLY t_idx; +DROP TABLE t;