@@ -1154,7 +1154,6 @@ SetDefaultACL(InternalDefaultACL *iacls)
11541154 Acl * def_acl ;
11551155 Acl * old_acl ;
11561156 Acl * new_acl ;
1157- HeapTuple newtuple ;
11581157 int noldmembers ;
11591158 int nnewmembers ;
11601159 Oid * oldmembers ;
@@ -1315,36 +1314,30 @@ SetDefaultACL(InternalDefaultACL *iacls)
13151314 }
13161315 else
13171316 {
1318- Datum values [Natts_pg_default_acl ] = {0 };
1319- bool nulls [Natts_pg_default_acl ] = {0 };
1320- bool replaces [Natts_pg_default_acl ] = {0 };
13211317 Oid defAclOid ;
13221318
1319+ CatalogUpdateValuesContext (pg_default_acl , ctx );
1320+
13231321 if (isNew )
13241322 {
13251323 /* insert new entry */
13261324 defAclOid = GetNewOidWithIndex (rel , DefaultAclOidIndexId ,
13271325 Anum_pg_default_acl_oid );
1328- values [Anum_pg_default_acl_oid - 1 ] = ObjectIdGetDatum (defAclOid );
1329- values [Anum_pg_default_acl_defaclrole - 1 ] = ObjectIdGetDatum (iacls -> roleid );
1330- values [Anum_pg_default_acl_defaclnamespace - 1 ] = ObjectIdGetDatum (iacls -> nspid );
1331- values [Anum_pg_default_acl_defaclobjtype - 1 ] = CharGetDatum (objtype );
1332- values [Anum_pg_default_acl_defaclacl - 1 ] = PointerGetDatum (new_acl );
1333-
1334- newtuple = heap_form_tuple (RelationGetDescr (rel ), values , nulls );
1335- CatalogTupleInsert (rel , newtuple );
1326+ CatalogTupleSetValue (ctx , pg_default_acl , oid , ObjectIdGetDatum (defAclOid ));
1327+ CatalogTupleSetValue (ctx , pg_default_acl , defaclrole , ObjectIdGetDatum (iacls -> roleid ));
1328+ CatalogTupleSetValue (ctx , pg_default_acl , defaclnamespace , ObjectIdGetDatum (iacls -> nspid ));
1329+ CatalogTupleSetValue (ctx , pg_default_acl , defaclobjtype , CharGetDatum (objtype ));
1330+ CatalogTupleSetValue (ctx , pg_default_acl , defaclacl , PointerGetDatum (new_acl ));
1331+
1332+ InsertCatalogTupleValues (rel , ctx );
13361333 }
13371334 else
13381335 {
13391336 defAclOid = ((Form_pg_default_acl ) GETSTRUCT (tuple ))-> oid ;
13401337
13411338 /* update existing entry */
1342- values [Anum_pg_default_acl_defaclacl - 1 ] = PointerGetDatum (new_acl );
1343- replaces [Anum_pg_default_acl_defaclacl - 1 ] = true;
1344-
1345- newtuple = heap_modify_tuple (tuple , RelationGetDescr (rel ),
1346- values , nulls , replaces );
1347- CatalogTupleUpdate (rel , & newtuple -> t_self , newtuple );
1339+ CatalogTupleUpdateValue (ctx , pg_default_acl , defaclacl , PointerGetDatum (new_acl ));
1340+ ModifyCatalogTupleValues (rel , tuple , ctx );
13481341 }
13491342
13501343 /* these dependencies don't change in an update */
@@ -1648,15 +1641,13 @@ ExecGrant_Attribute(InternalGrant *istmt, Oid relOid, const char *relname,
16481641 Oid grantorId ;
16491642 AclMode avail_goptions ;
16501643 bool need_update ;
1651- HeapTuple newtuple ;
1652- Datum values [Natts_pg_attribute ] = {0 };
1653- bool nulls [Natts_pg_attribute ] = {0 };
1654- bool replaces [Natts_pg_attribute ] = {0 };
16551644 int noldmembers ;
16561645 int nnewmembers ;
16571646 Oid * oldmembers ;
16581647 Oid * newmembers ;
16591648
1649+ CatalogUpdateValuesContext (pg_attribute , ctx );
1650+
16601651 attr_tuple = SearchSysCache2 (ATTNUM ,
16611652 ObjectIdGetDatum (relOid ),
16621653 Int16GetDatum (attnum ));
@@ -1742,22 +1733,18 @@ ExecGrant_Attribute(InternalGrant *istmt, Oid relOid, const char *relname,
17421733 */
17431734 if (ACL_NUM (new_acl ) > 0 )
17441735 {
1745- values [ Anum_pg_attribute_attacl - 1 ] = PointerGetDatum (new_acl );
1736+ CatalogTupleUpdateValue ( ctx , pg_attribute , attacl , PointerGetDatum (new_acl ) );
17461737 need_update = true;
17471738 }
17481739 else
17491740 {
1750- nulls [ Anum_pg_attribute_attacl - 1 ] = true ;
1741+ CatalogTupleUpdateValueNull ( ctx , pg_attribute , attacl ) ;
17511742 need_update = !isNull ;
17521743 }
1753- replaces [Anum_pg_attribute_attacl - 1 ] = true;
17541744
17551745 if (need_update )
17561746 {
1757- newtuple = heap_modify_tuple (attr_tuple , RelationGetDescr (attRelation ),
1758- values , nulls , replaces );
1759-
1760- CatalogTupleUpdate (attRelation , & newtuple -> t_self , newtuple );
1747+ ModifyCatalogTupleValues (attRelation , attr_tuple , ctx );
17611748
17621749 /* Update initial privileges for extensions */
17631750 recordExtensionInitPriv (relOid , RelationRelationId , attnum ,
@@ -1958,14 +1945,12 @@ ExecGrant_Relation(InternalGrant *istmt)
19581945 AclMode avail_goptions ;
19591946 Acl * new_acl ;
19601947 Oid grantorId ;
1961- HeapTuple newtuple ;
1962- Datum values [Natts_pg_class ] = {0 };
1963- bool nulls [Natts_pg_class ] = {0 };
1964- bool replaces [Natts_pg_class ] = {0 };
19651948 int nnewmembers ;
19661949 Oid * newmembers ;
19671950 ObjectType objtype ;
19681951
1952+ CatalogUpdateValuesContext (pg_class , ctx );
1953+
19691954 /* Determine ID to do the grant as, and available grant options */
19701955 select_best_grantor (GetUserId (), this_privileges ,
19711956 old_acl , ownerId ,
@@ -2011,13 +1996,8 @@ ExecGrant_Relation(InternalGrant *istmt)
20111996 nnewmembers = aclmembers (new_acl , & newmembers );
20121997
20131998 /* finished building new ACL value, now insert it */
2014- replaces [Anum_pg_class_relacl - 1 ] = true;
2015- values [Anum_pg_class_relacl - 1 ] = PointerGetDatum (new_acl );
2016-
2017- newtuple = heap_modify_tuple (tuple , RelationGetDescr (relation ),
2018- values , nulls , replaces );
2019-
2020- CatalogTupleUpdate (relation , & newtuple -> t_self , newtuple );
1999+ CatalogTupleUpdateValue (ctx , pg_class , relacl , PointerGetDatum (new_acl ));
2000+ ModifyCatalogTupleValues (relation , tuple , ctx );
20212001 UnlockTuple (relation , & tuple -> t_self , InplaceUpdateTupleLock );
20222002
20232003 /* Update initial privileges for extensions */
@@ -2140,7 +2120,7 @@ ExecGrant_common(InternalGrant *istmt, Oid classid, AclMode default_privs,
21402120 HeapTuple newtuple ;
21412121 Datum * values = palloc0_array (Datum , RelationGetDescr (relation )-> natts );
21422122 bool * nulls = palloc0_array (bool , RelationGetDescr (relation )-> natts );
2143- bool * replaces = palloc0_array ( bool , RelationGetDescr ( relation ) -> natts ) ;
2123+ Bitmapset * updated = NULL ;
21442124 int noldmembers ;
21452125 int nnewmembers ;
21462126 Oid * oldmembers ;
@@ -2214,14 +2194,17 @@ ExecGrant_common(InternalGrant *istmt, Oid classid, AclMode default_privs,
22142194 */
22152195 nnewmembers = aclmembers (new_acl , & newmembers );
22162196
2217- /* finished building new ACL value, now insert it */
2218- replaces [get_object_attnum_acl (classid ) - 1 ] = true;
2197+ /*
2198+ * Finished building new ACL value, now insert it. NOTE: We can't use
2199+ * the CatalogTuple*() macros here because
2200+ * get_object_attnum_acl(classid) provides an index.
2201+ */
22192202 values [get_object_attnum_acl (classid ) - 1 ] = PointerGetDatum (new_acl );
2203+ updated = bms_add_member (updated , get_object_attnum_acl (classid ) - FirstLowInvalidHeapAttributeNumber );
22202204
2221- newtuple = heap_modify_tuple (tuple , RelationGetDescr (relation ), values ,
2222- nulls , replaces );
2205+ newtuple = heap_update_tuple (tuple , RelationGetDescr (relation ), values , nulls , updated );
22232206
2224- CatalogTupleUpdate (relation , & newtuple -> t_self , newtuple );
2207+ CatalogTupleUpdate (relation , & newtuple -> t_self , newtuple , updated , NULL );
22252208 UnlockTuple (relation , & tuple -> t_self , InplaceUpdateTupleLock );
22262209
22272210 /* Update initial privileges for extensions */
@@ -2237,6 +2220,7 @@ ExecGrant_common(InternalGrant *istmt, Oid classid, AclMode default_privs,
22372220 ReleaseSysCache (tuple );
22382221
22392222 pfree (new_acl );
2223+ bms_free (updated );
22402224
22412225 /* prevent error when processing duplicate objects */
22422226 CommandCounterIncrement ();
@@ -2286,10 +2270,6 @@ ExecGrant_Largeobject(InternalGrant *istmt)
22862270 Acl * new_acl ;
22872271 Oid grantorId ;
22882272 Oid ownerId ;
2289- HeapTuple newtuple ;
2290- Datum values [Natts_pg_largeobject_metadata ] = {0 };
2291- bool nulls [Natts_pg_largeobject_metadata ] = {0 };
2292- bool replaces [Natts_pg_largeobject_metadata ] = {0 };
22932273 int noldmembers ;
22942274 int nnewmembers ;
22952275 Oid * oldmembers ;
@@ -2298,6 +2278,8 @@ ExecGrant_Largeobject(InternalGrant *istmt)
22982278 SysScanDesc scan ;
22992279 HeapTuple tuple ;
23002280
2281+ CatalogUpdateValuesContext (pg_largeobject_metadata , ctx );
2282+
23012283 /* There's no syscache for pg_largeobject_metadata */
23022284 ScanKeyInit (& entry [0 ],
23032285 Anum_pg_largeobject_metadata_oid ,
@@ -2367,14 +2349,8 @@ ExecGrant_Largeobject(InternalGrant *istmt)
23672349 nnewmembers = aclmembers (new_acl , & newmembers );
23682350
23692351 /* finished building new ACL value, now insert it */
2370- replaces [Anum_pg_largeobject_metadata_lomacl - 1 ] = true;
2371- values [Anum_pg_largeobject_metadata_lomacl - 1 ]
2372- = PointerGetDatum (new_acl );
2373-
2374- newtuple = heap_modify_tuple (tuple , RelationGetDescr (relation ),
2375- values , nulls , replaces );
2376-
2377- CatalogTupleUpdate (relation , & newtuple -> t_self , newtuple );
2352+ CatalogTupleUpdateValue (ctx , pg_largeobject_metadata , lomacl , PointerGetDatum (new_acl ));
2353+ ModifyCatalogTupleValues (relation , tuple , ctx );
23782354
23792355 /* Update initial privileges for extensions */
23802356 recordExtensionInitPriv (loid , LargeObjectRelationId , 0 , new_acl );
@@ -2524,19 +2500,11 @@ ExecGrant_Parameter(InternalGrant *istmt)
25242500 }
25252501 else
25262502 {
2527- /* finished building new ACL value, now insert it */
2528- HeapTuple newtuple ;
2529- Datum values [Natts_pg_parameter_acl ] = {0 };
2530- bool nulls [Natts_pg_parameter_acl ] = {0 };
2531- bool replaces [Natts_pg_parameter_acl ] = {0 };
2532-
2533- replaces [Anum_pg_parameter_acl_paracl - 1 ] = true;
2534- values [Anum_pg_parameter_acl_paracl - 1 ] = PointerGetDatum (new_acl );
2535-
2536- newtuple = heap_modify_tuple (tuple , RelationGetDescr (relation ),
2537- values , nulls , replaces );
2503+ /* finished building new ACL value, now update it */
2504+ CatalogUpdateValuesContext (pg_parameter_acl , ctx );
25382505
2539- CatalogTupleUpdate (relation , & newtuple -> t_self , newtuple );
2506+ CatalogTupleUpdateValue (ctx , pg_parameter_acl , paracl , PointerGetDatum (new_acl ));
2507+ ModifyCatalogTupleValues (relation , tuple , ctx );
25402508 }
25412509
25422510 /* Update initial privileges for extensions */
@@ -4631,7 +4599,6 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid,
46314599 Relation relation ;
46324600 ScanKeyData key [3 ];
46334601 SysScanDesc scan ;
4634- HeapTuple tuple ;
46354602 HeapTuple oldtuple ;
46364603 int noldmembers ;
46374604 int nnewmembers ;
@@ -4666,9 +4633,6 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid,
46664633 /* If we find an entry, update it with the latest ACL. */
46674634 if (HeapTupleIsValid (oldtuple ))
46684635 {
4669- Datum values [Natts_pg_init_privs ] = {0 };
4670- bool nulls [Natts_pg_init_privs ] = {0 };
4671- bool replace [Natts_pg_init_privs ] = {0 };
46724636 Datum oldAclDatum ;
46734637 bool isNull ;
46744638 Acl * old_acl ;
@@ -4687,13 +4651,10 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid,
46874651 /* If we have a new ACL to set, then update the row with it. */
46884652 if (new_acl && ACL_NUM (new_acl ) != 0 )
46894653 {
4690- values [Anum_pg_init_privs_initprivs - 1 ] = PointerGetDatum (new_acl );
4691- replace [Anum_pg_init_privs_initprivs - 1 ] = true;
4692-
4693- oldtuple = heap_modify_tuple (oldtuple , RelationGetDescr (relation ),
4694- values , nulls , replace );
4654+ CatalogUpdateValuesContext (pg_init_privs , ctx );
46954655
4696- CatalogTupleUpdate (relation , & oldtuple -> t_self , oldtuple );
4656+ CatalogTupleUpdateValue (ctx , pg_init_privs , initprivs , PointerGetDatum (new_acl ));
4657+ ModifyCatalogTupleValues (relation , oldtuple , ctx );
46974658 }
46984659 else
46994660 {
@@ -4703,8 +4664,7 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid,
47034664 }
47044665 else
47054666 {
4706- Datum values [Natts_pg_init_privs ] = {0 };
4707- bool nulls [Natts_pg_init_privs ] = {0 };
4667+ CatalogInsertValuesContext (pg_init_privs , ctx );
47084668
47094669 /*
47104670 * Only add a new entry if the new ACL is non-NULL.
@@ -4715,19 +4675,15 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid,
47154675 if (new_acl && ACL_NUM (new_acl ) != 0 )
47164676 {
47174677 /* No entry found, so add it. */
4718- values [ Anum_pg_init_privs_objoid - 1 ] = ObjectIdGetDatum (objoid );
4719- values [ Anum_pg_init_privs_classoid - 1 ] = ObjectIdGetDatum (classoid );
4720- values [ Anum_pg_init_privs_objsubid - 1 ] = Int32GetDatum (objsubid );
4678+ CatalogTupleSetValue ( ctx , pg_init_privs , objoid , ObjectIdGetDatum (objoid ) );
4679+ CatalogTupleSetValue ( ctx , pg_init_privs , classoid , ObjectIdGetDatum (classoid ) );
4680+ CatalogTupleSetValue ( ctx , pg_init_privs , objsubid , Int32GetDatum (objsubid ) );
47214681
47224682 /* This function only handles initial privileges of extensions */
4723- values [Anum_pg_init_privs_privtype - 1 ] =
4724- CharGetDatum (INITPRIVS_EXTENSION );
4725-
4726- values [Anum_pg_init_privs_initprivs - 1 ] = PointerGetDatum (new_acl );
4683+ CatalogTupleSetValue (ctx , pg_init_privs , privtype , CharGetDatum (INITPRIVS_EXTENSION ));
4684+ CatalogTupleSetValue (ctx , pg_init_privs , initprivs , PointerGetDatum (new_acl ));
47274685
4728- tuple = heap_form_tuple (RelationGetDescr (relation ), values , nulls );
4729-
4730- CatalogTupleInsert (relation , tuple );
4686+ InsertCatalogTupleValues (relation , ctx );
47314687
47324688 /* Update pg_shdepend, too. */
47334689 noldmembers = 0 ;
@@ -4764,7 +4720,6 @@ ReplaceRoleInInitPriv(Oid oldroleid, Oid newroleid,
47644720 bool isNull ;
47654721 Acl * old_acl ;
47664722 Acl * new_acl ;
4767- HeapTuple newtuple ;
47684723 int noldmembers ;
47694724 int nnewmembers ;
47704725 Oid * oldmembers ;
@@ -4825,17 +4780,11 @@ ReplaceRoleInInitPriv(Oid oldroleid, Oid newroleid,
48254780 }
48264781 else
48274782 {
4828- Datum values [Natts_pg_init_privs ] = {0 };
4829- bool nulls [Natts_pg_init_privs ] = {0 };
4830- bool replaces [Natts_pg_init_privs ] = {0 };
4831-
48324783 /* Update existing entry. */
4833- values [Anum_pg_init_privs_initprivs - 1 ] = PointerGetDatum (new_acl );
4834- replaces [Anum_pg_init_privs_initprivs - 1 ] = true;
4784+ CatalogUpdateValuesContext (pg_init_privs , ctx );
48354785
4836- newtuple = heap_modify_tuple (oldtuple , RelationGetDescr (rel ),
4837- values , nulls , replaces );
4838- CatalogTupleUpdate (rel , & newtuple -> t_self , newtuple );
4786+ CatalogTupleUpdateValue (ctx , pg_init_privs , initprivs , PointerGetDatum (new_acl ));
4787+ ModifyCatalogTupleValues (rel , oldtuple , ctx );
48394788 }
48404789
48414790 /*
@@ -4875,7 +4824,6 @@ RemoveRoleFromInitPriv(Oid roleid, Oid classid, Oid objid, int32 objsubid)
48754824 bool isNull ;
48764825 Acl * old_acl ;
48774826 Acl * new_acl ;
4878- HeapTuple newtuple ;
48794827 int noldmembers ;
48804828 int nnewmembers ;
48814829 Oid * oldmembers ;
@@ -4961,17 +4909,11 @@ RemoveRoleFromInitPriv(Oid roleid, Oid classid, Oid objid, int32 objsubid)
49614909 }
49624910 else
49634911 {
4964- Datum values [Natts_pg_init_privs ] = {0 };
4965- bool nulls [Natts_pg_init_privs ] = {0 };
4966- bool replaces [Natts_pg_init_privs ] = {0 };
4967-
49684912 /* Update existing entry. */
4969- values [Anum_pg_init_privs_initprivs - 1 ] = PointerGetDatum (new_acl );
4970- replaces [Anum_pg_init_privs_initprivs - 1 ] = true;
4913+ CatalogUpdateValuesContext (pg_init_privs , ctx );
49714914
4972- newtuple = heap_modify_tuple (oldtuple , RelationGetDescr (rel ),
4973- values , nulls , replaces );
4974- CatalogTupleUpdate (rel , & newtuple -> t_self , newtuple );
4915+ CatalogTupleUpdateValue (ctx , pg_init_privs , initprivs , PointerGetDatum (new_acl ));
4916+ ModifyCatalogTupleValues (rel , oldtuple , ctx );
49754917 }
49764918
49774919 /*
0 commit comments