提交 eb2961bb 编写于 作者: P Pengzhou Tang 提交者: Amil Khanzada

Add a syscache for pg_resgroup

This commit is a modified version of 8286b61f76014d1f3d58176ec3f12bb2dc9a9dcc,
the only difference is we put new entries to the end of cacheinfo array, so extensions
like madlib, plcontainer who linked with syscache.h can still have the same cache
identifier value.
上级 4410989b
......@@ -380,7 +380,7 @@ AlterResourceGroup(AlterResourceGroupStmt *stmt)
* Check the pg_resgroup relation to be certain the resource group already
* exists.
*/
groupid = GetResGroupIdForName(stmt->name, RowExclusiveLock);
groupid = GetResGroupIdForName(stmt->name);
if (groupid == InvalidOid)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
......@@ -612,32 +612,27 @@ GetResGroupIdForRole(Oid roleid)
* to Oid.
*/
Oid
GetResGroupIdForName(const char *name, LOCKMODE lockmode)
GetResGroupIdForName(const char *name)
{
Relation rel;
ScanKeyData scankey;
SysScanDesc scan;
HeapTuple tuple;
Oid rsgid;
rel = heap_open(ResGroupRelationId, lockmode);
tuple = SearchSysCache1(WRESGROUPNAME,
CStringGetDatum(name));
/* SELECT oid FROM pg_resgroup WHERE rsgname = :1 */
ScanKeyInit(&scankey,
Anum_pg_resgroup_rsgname,
BTEqualStrategyNumber, F_NAMEEQ,
CStringGetDatum(name));
scan = systable_beginscan(rel, ResGroupRsgnameIndexId, true,
SnapshotNow, 1, &scankey);
tuple = systable_getnext(scan);
if (HeapTupleIsValid(tuple))
rsgid = HeapTupleGetOid(tuple);
{
bool isnull;
Datum oidDatum = SysCacheGetAttr(WRESGROUPNAME, tuple,
ObjectIdAttributeNumber,
&isnull);
Assert (!isnull);
rsgid = DatumGetObjectId(oidDatum);
}
else
rsgid = InvalidOid;
return InvalidOid;
systable_endscan(scan);
heap_close(rel, lockmode);
ReleaseSysCache(tuple);
return rsgid;
}
......@@ -646,37 +641,28 @@ GetResGroupIdForName(const char *name, LOCKMODE lockmode)
* GetResGroupNameForId -- Return the resource group name for an Oid
*/
char *
GetResGroupNameForId(Oid oid, LOCKMODE lockmode)
GetResGroupNameForId(Oid oid)
{
Relation rel;
ScanKeyData scankey;
SysScanDesc scan;
HeapTuple tuple;
char *name = NULL;
rel = heap_open(ResGroupRelationId, lockmode);
/* SELECT rsgname FROM pg_resgroup WHERE oid = :1 */
ScanKeyInit(&scankey,
ObjectIdAttributeNumber,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(oid));
scan = systable_beginscan(rel, ResGroupOidIndexId, true,
SnapshotNow, 1, &scankey);
tuple = SearchSysCache1(WRESGROUPOID,
ObjectIdGetDatum(oid));
tuple = systable_getnext(scan);
if (HeapTupleIsValid(tuple))
{
bool isnull;
Datum nameDatum = heap_getattr(tuple, Anum_pg_resgroup_rsgname,
rel->rd_att, &isnull);
Datum nameDatum = SysCacheGetAttr(WRESGROUPOID, tuple,
Anum_pg_resgroup_rsgname,
&isnull);
Assert (!isnull);
Name resGroupName = DatumGetName(nameDatum);
name = pstrdup(NameStr(*resGroupName));
}
else
return "unknow";
systable_endscan(scan);
heap_close(rel, lockmode);
ReleaseSysCache(tuple);
return name;
}
......
......@@ -533,7 +533,7 @@ CreateRole(CreateRoleStmt *stmt)
{
Oid rsgid;
rsgid = GetResGroupIdForName(resgroup, ShareLock);
rsgid = GetResGroupIdForName(resgroup);
if (rsgid == InvalidOid)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
......@@ -1195,7 +1195,7 @@ AlterRole(AlterRoleStmt *stmt)
resgroup)));
}
rsgid = GetResGroupIdForName(resgroup, ShareLock);
rsgid = GetResGroupIdForName(resgroup);
if (rsgid == InvalidOid)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
......
......@@ -633,7 +633,7 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
if (funcctx->tuple_desc->natts > 13)
{
Datum now = TimestampTzGetDatum(GetCurrentTimestamp());
char *groupName = GetResGroupNameForId(beentry->st_rsgid, AccessShareLock);
char *groupName = GetResGroupNameForId(beentry->st_rsgid);
values[13] = ObjectIdGetDatum(beentry->st_rsgid);
......
......@@ -54,6 +54,7 @@
#include "catalog/pg_ts_template.h"
#include "catalog/pg_type.h"
#include "catalog/pg_window.h"
#include "catalog/pg_resgroup.h"
#include "utils/syscache.h"
......@@ -662,6 +663,28 @@ static const struct cachedesc cacheinfo[] = {
0
},
32
},
{ResGroupRelationId, /* WRESGROUPNAME */
ResGroupRsgnameIndexId,
1,
{
Anum_pg_resgroup_rsgname,
0,
0,
0
},
128
},
{ResGroupRelationId, /* WRESGROUPOID */
ResGroupOidIndexId,
1,
{
ObjectIdAttributeNumber,
0,
0,
0
},
128
}
};
......
......@@ -32,8 +32,8 @@ extern void DropResourceGroup(DropResourceGroupStmt *stmt);
extern void AlterResourceGroup(AlterResourceGroupStmt *stmt);
/* catalog access function */
extern Oid GetResGroupIdForName(const char *name, LOCKMODE lockmode);
extern char *GetResGroupNameForId(Oid oid, LOCKMODE lockmode);
extern Oid GetResGroupIdForName(const char *name);
extern char *GetResGroupNameForId(Oid oid);
extern Oid GetResGroupIdForRole(Oid roleid);
extern void GetResGroupCapabilities(Relation rel,
Oid groupId,
......
......@@ -79,7 +79,9 @@ enum SysCacheIdentifier
TSTEMPLATEOID,
TYPENAMENSP,
TYPEOID,
WINFNOID
WINFNOID,
WRESGROUPNAME,
WRESGROUPOID
};
extern void InitCatalogCache(void);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册