Skip to content

Commit 03a542b

Browse files
committed
Avoid unnecessary fetch from pg_shadow in the normal case in
pg_class_aclmask(). We only need to do this when we have to check pg_shadow.usecatupd, and that's not relevant unless the target table is a system catalog. So we can usually avoid one syscache lookup.
1 parent 140b078 commit 03a542b

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

src/backend/catalog/aclchk.c

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.111 2005/04/14 20:03:23 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.112 2005/05/29 23:38:05 tgl Exp $
1212
*
1313
* NOTES
1414
* See acl.h.
@@ -1310,6 +1310,29 @@ aclcheck_error(AclResult aclerr, AclObjectKind objectkind,
13101310
}
13111311

13121312

1313+
/* Check if given userid has usecatupd privilege according to pg_shadow */
1314+
static bool
1315+
has_usecatupd(AclId userid)
1316+
{
1317+
bool usecatupd;
1318+
HeapTuple tuple;
1319+
1320+
tuple = SearchSysCache(SHADOWSYSID,
1321+
ObjectIdGetDatum(userid),
1322+
0, 0, 0);
1323+
if (!HeapTupleIsValid(tuple))
1324+
ereport(ERROR,
1325+
(errcode(ERRCODE_UNDEFINED_OBJECT),
1326+
errmsg("user with ID %u does not exist", userid)));
1327+
1328+
usecatupd = ((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd;
1329+
1330+
ReleaseSysCache(tuple);
1331+
1332+
return usecatupd;
1333+
}
1334+
1335+
13131336
/*
13141337
* Exported routine for examining a user's privileges for a table
13151338
*
@@ -1325,8 +1348,6 @@ pg_class_aclmask(Oid table_oid, AclId userid,
13251348
AclMode mask, AclMaskHow how)
13261349
{
13271350
AclMode result;
1328-
bool usesuper,
1329-
usecatupd;
13301351
HeapTuple tuple;
13311352
Form_pg_class classForm;
13321353
Datum aclDatum;
@@ -1335,24 +1356,7 @@ pg_class_aclmask(Oid table_oid, AclId userid,
13351356
AclId ownerId;
13361357

13371358
/*
1338-
* Validate userid, find out if he is superuser, also get usecatupd
1339-
*/
1340-
tuple = SearchSysCache(SHADOWSYSID,
1341-
ObjectIdGetDatum(userid),
1342-
0, 0, 0);
1343-
if (!HeapTupleIsValid(tuple))
1344-
ereport(ERROR,
1345-
(errcode(ERRCODE_UNDEFINED_OBJECT),
1346-
errmsg("user with ID %u does not exist", userid)));
1347-
1348-
usecatupd = ((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd;
1349-
1350-
ReleaseSysCache(tuple);
1351-
1352-
usesuper = superuser_arg(userid);
1353-
1354-
/*
1355-
* Now get the relation's tuple from pg_class
1359+
* Must get the relation's tuple from pg_class
13561360
*/
13571361
tuple = SearchSysCache(RELOID,
13581362
ObjectIdGetDatum(table_oid),
@@ -1377,7 +1381,7 @@ pg_class_aclmask(Oid table_oid, AclId userid,
13771381
if ((mask & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) &&
13781382
IsSystemClass(classForm) &&
13791383
classForm->relkind != RELKIND_VIEW &&
1380-
!usecatupd &&
1384+
!has_usecatupd(userid) &&
13811385
!allowSystemTableMods)
13821386
{
13831387
#ifdef ACLDEBUG
@@ -1389,7 +1393,7 @@ pg_class_aclmask(Oid table_oid, AclId userid,
13891393
/*
13901394
* Otherwise, superusers bypass all permission-checking.
13911395
*/
1392-
if (usesuper)
1396+
if (superuser_arg(userid))
13931397
{
13941398
#ifdef ACLDEBUG
13951399
elog(DEBUG2, "%u is superuser, home free", userid);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy