diff --git a/src/backend/commands/resgroupcmds.c b/src/backend/commands/resgroupcmds.c index 384675edb7f..e5ba72a3054 100644 --- a/src/backend/commands/resgroupcmds.c +++ b/src/backend/commands/resgroupcmds.c @@ -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)); 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;