Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 11 additions & 33 deletions src/backend/commands/resgroupcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,47 +715,25 @@ GetResGroupIdForRole(Oid roleid)
{
HeapTuple tuple;
Oid groupId;
bool isNull;
Relation rel;
ScanKeyData key;
SysScanDesc sscan;

rel = table_open(AuthIdRelationId, AccessShareLock);

ScanKeyInit(&key,
Anum_pg_authid_oid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(roleid));

sscan = systable_beginscan(rel, AuthIdOidIndexId, true, NULL, 1, &key);
bool isNull = true;

tuple = systable_getnext(sscan);
/*
* Prefer syscache lookup to avoid taking explicit catalog scan/snapshot
* which may install xmin in the current process. Use the AUTHOID
* syscache to fetch pg_authid tuple for the given role Oid.
*/
tuple = SearchSysCache1(AUTHOID, ObjectIdGetDatum(roleid));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add related test create index concurrently t_idx on t(a, b); ?

if (!HeapTupleIsValid(tuple))
{
systable_endscan(sscan);
table_close(rel, AccessShareLock);

/*
* Role should have been dropped by other backends in this case, so this
* session cannot execute any command anymore
*/
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("role with Oid %u was dropped", roleid),
errdetail("Cannot execute commands anymore, please terminate this session.")));
errmsg("role with Oid %u was dropped", roleid),
errdetail("Cannot execute commands anymore, please terminate this session.")));
}

/* must access tuple before systable_endscan */
groupId = DatumGetObjectId(heap_getattr(tuple, Anum_pg_authid_rolresgroup,
rel->rd_att, &isNull));
groupId = DatumGetObjectId(SysCacheGetAttr(AUTHOID, tuple, Anum_pg_authid_rolresgroup, &isNull));

systable_endscan(sscan);

/*
* release lock here to guarantee we have no lock held when acquiring
* resource group slot
*/
table_close(rel, AccessShareLock);
ReleaseSysCache(tuple);

if (!OidIsValid(groupId))
groupId = InvalidOid;
Expand Down
Loading