Skip to content

Commit 864e0e1

Browse files
committed
Fix assert failure triggered by "CREATE INDEX CONCURRENTLY"
When resource group is enabled, StartTransaction() may acquire a catalog snapshot within GetResGroupIdForRole, resulting in a valid xmin. However, the transaction status does not meet the requirements for "CREATE INDEX CONCURRENTLY".
1 parent 7e4978e commit 864e0e1

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

src/backend/commands/resgroupcmds.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "commands/resgroupcmds.h"
3535
#include "miscadmin.h"
3636
#include "nodes/pg_list.h"
37+
#include "storage/proc.h"
3738
#include "utils/builtins.h"
3839
#include "utils/datetime.h"
3940
#include "utils/fmgroids.h"
@@ -716,10 +717,17 @@ GetResGroupIdForRole(Oid roleid)
716717
HeapTuple tuple;
717718
Oid groupId;
718719
bool isNull;
720+
bool releaseSnapshot;
719721
Relation rel;
720722
ScanKeyData key;
721723
SysScanDesc sscan;
722724

725+
/*
726+
* StartTransaction() might hold a catalog snapshot with a valid xmin.
727+
* As this fails the "CREATE INDEX CONCURRENTLY" status checks, explicitly
728+
* release the snapshot.
729+
*/
730+
releaseSnapshot = MyProc->xmin == InvalidTransactionId;
723731
rel = table_open(AuthIdRelationId, AccessShareLock);
724732

725733
ScanKeyInit(&key,
@@ -757,6 +765,9 @@ GetResGroupIdForRole(Oid roleid)
757765
*/
758766
table_close(rel, AccessShareLock);
759767

768+
if (releaseSnapshot)
769+
InvalidateCatalogSnapshot();
770+
760771
if (!OidIsValid(groupId))
761772
groupId = InvalidOid;
762773

src/test/isolation2/expected/resgroup/resgroup_transaction.out

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,16 @@ DROP
237237
-- cleanup
238238
DROP VIEW rg_test_monitor;
239239
DROP
240+
241+
-- ----------------------------------------------------------------------
242+
-- Test: "CREATE INDEX CONCURRENTLY" when compiled with enable-cassert
243+
-- ----------------------------------------------------------------------
244+
245+
CREATE TABLE t(a text, b text);
246+
CREATE
247+
CREATE INDEX CONCURRENTLY t_idx ON t(a, b);
248+
CREATE
249+
DROP INDEX CONCURRENTLY t_idx;
250+
DROP
251+
DROP TABLE t;
252+
DROP

src/test/isolation2/sql/resgroup/resgroup_transaction.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,12 @@ DROP FUNCTION rg_drop_func();
134134

135135
-- cleanup
136136
DROP VIEW rg_test_monitor;
137+
138+
-- ----------------------------------------------------------------------
139+
-- Test: "CREATE INDEX CONCURRENTLY" when compiled with enable-cassert
140+
-- ----------------------------------------------------------------------
141+
142+
CREATE TABLE t(a text, b text);
143+
CREATE INDEX CONCURRENTLY t_idx ON t(a, b);
144+
DROP INDEX CONCURRENTLY t_idx;
145+
DROP TABLE t;

0 commit comments

Comments
 (0)