8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.159 2010/01/02 16:57:36 momjian Exp $
11
+ * $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.160 2010/01/05 21:53:58 rhaas Exp $
12
12
*
13
13
* NOTES
14
14
* See acl.h.
@@ -2783,18 +2783,11 @@ ExecGrant_Tablespace(InternalGrant *istmt)
2783
2783
int nnewmembers ;
2784
2784
Oid * oldmembers ;
2785
2785
Oid * newmembers ;
2786
- ScanKeyData entry [1 ];
2787
- SysScanDesc scan ;
2788
2786
HeapTuple tuple ;
2789
2787
2790
- /* There's no syscache for pg_tablespace, so must look the hard way */
2791
- ScanKeyInit (& entry [0 ],
2792
- ObjectIdAttributeNumber ,
2793
- BTEqualStrategyNumber , F_OIDEQ ,
2794
- ObjectIdGetDatum (tblId ));
2795
- scan = systable_beginscan (relation , TablespaceOidIndexId , true,
2796
- SnapshotNow , 1 , entry );
2797
- tuple = systable_getnext (scan );
2788
+ /* Search syscache for pg_tablespace */
2789
+ tuple = SearchSysCache (TABLESPACEOID , ObjectIdGetDatum (tblId ),
2790
+ 0 , 0 , 0 );
2798
2791
if (!HeapTupleIsValid (tuple ))
2799
2792
elog (ERROR , "cache lookup failed for tablespace %u" , tblId );
2800
2793
@@ -2865,8 +2858,7 @@ ExecGrant_Tablespace(InternalGrant *istmt)
2865
2858
noldmembers , oldmembers ,
2866
2859
nnewmembers , newmembers );
2867
2860
2868
- systable_endscan (scan );
2869
-
2861
+ ReleaseSysCache (tuple );
2870
2862
pfree (new_acl );
2871
2863
2872
2864
/* prevent error when processing duplicate objects */
@@ -3696,9 +3688,6 @@ pg_tablespace_aclmask(Oid spc_oid, Oid roleid,
3696
3688
AclMode mask , AclMaskHow how )
3697
3689
{
3698
3690
AclMode result ;
3699
- Relation pg_tablespace ;
3700
- ScanKeyData entry [1 ];
3701
- SysScanDesc scan ;
3702
3691
HeapTuple tuple ;
3703
3692
Datum aclDatum ;
3704
3693
bool isNull ;
@@ -3711,26 +3700,19 @@ pg_tablespace_aclmask(Oid spc_oid, Oid roleid,
3711
3700
3712
3701
/*
3713
3702
* Get the tablespace's ACL from pg_tablespace
3714
- *
3715
- * There's no syscache for pg_tablespace, so must look the hard way
3716
3703
*/
3717
- pg_tablespace = heap_open (TableSpaceRelationId , AccessShareLock );
3718
- ScanKeyInit (& entry [0 ],
3719
- ObjectIdAttributeNumber ,
3720
- BTEqualStrategyNumber , F_OIDEQ ,
3721
- ObjectIdGetDatum (spc_oid ));
3722
- scan = systable_beginscan (pg_tablespace , TablespaceOidIndexId , true,
3723
- SnapshotNow , 1 , entry );
3724
- tuple = systable_getnext (scan );
3704
+ tuple = SearchSysCache (TABLESPACEOID , ObjectIdGetDatum (spc_oid ),
3705
+ 0 , 0 , 0 );
3725
3706
if (!HeapTupleIsValid (tuple ))
3726
3707
ereport (ERROR ,
3727
3708
(errcode (ERRCODE_UNDEFINED_OBJECT ),
3728
3709
errmsg ("tablespace with OID %u does not exist" , spc_oid )));
3729
3710
3730
3711
ownerId = ((Form_pg_tablespace ) GETSTRUCT (tuple ))-> spcowner ;
3731
3712
3732
- aclDatum = heap_getattr (tuple , Anum_pg_tablespace_spcacl ,
3733
- RelationGetDescr (pg_tablespace ), & isNull );
3713
+ aclDatum = SysCacheGetAttr (TABLESPACEOID , tuple ,
3714
+ Anum_pg_tablespace_spcacl ,
3715
+ & isNull );
3734
3716
3735
3717
if (isNull )
3736
3718
{
@@ -3750,8 +3732,7 @@ pg_tablespace_aclmask(Oid spc_oid, Oid roleid,
3750
3732
if (acl && (Pointer ) acl != DatumGetPointer (aclDatum ))
3751
3733
pfree (acl );
3752
3734
3753
- systable_endscan (scan );
3754
- heap_close (pg_tablespace , AccessShareLock );
3735
+ ReleaseSysCache (tuple );
3755
3736
3756
3737
return result ;
3757
3738
}
@@ -4338,36 +4319,24 @@ pg_namespace_ownercheck(Oid nsp_oid, Oid roleid)
4338
4319
bool
4339
4320
pg_tablespace_ownercheck (Oid spc_oid , Oid roleid )
4340
4321
{
4341
- Relation pg_tablespace ;
4342
- ScanKeyData entry [1 ];
4343
- SysScanDesc scan ;
4344
4322
HeapTuple spctuple ;
4345
4323
Oid spcowner ;
4346
4324
4347
4325
/* Superusers bypass all permission checking. */
4348
4326
if (superuser_arg (roleid ))
4349
4327
return true;
4350
4328
4351
- /* There's no syscache for pg_tablespace, so must look the hard way */
4352
- pg_tablespace = heap_open (TableSpaceRelationId , AccessShareLock );
4353
- ScanKeyInit (& entry [0 ],
4354
- ObjectIdAttributeNumber ,
4355
- BTEqualStrategyNumber , F_OIDEQ ,
4356
- ObjectIdGetDatum (spc_oid ));
4357
- scan = systable_beginscan (pg_tablespace , TablespaceOidIndexId , true,
4358
- SnapshotNow , 1 , entry );
4359
-
4360
- spctuple = systable_getnext (scan );
4361
-
4329
+ /* Search syscache for pg_tablespace */
4330
+ spctuple = SearchSysCache (TABLESPACEOID , ObjectIdGetDatum (spc_oid ),
4331
+ 0 , 0 , 0 );
4362
4332
if (!HeapTupleIsValid (spctuple ))
4363
4333
ereport (ERROR ,
4364
4334
(errcode (ERRCODE_UNDEFINED_OBJECT ),
4365
4335
errmsg ("tablespace with OID %u does not exist" , spc_oid )));
4366
4336
4367
4337
spcowner = ((Form_pg_tablespace ) GETSTRUCT (spctuple ))-> spcowner ;
4368
4338
4369
- systable_endscan (scan );
4370
- heap_close (pg_tablespace , AccessShareLock );
4339
+ ReleaseSysCache (spctuple );
4371
4340
4372
4341
return has_privs_of_role (roleid , spcowner );
4373
4342
}
0 commit comments