From c06b5b99bbb0d0e5ddeea9661ec7678e3cf53b4c Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Wed, 18 Feb 2026 09:25:52 +0900 Subject: [PATCH] Add concept of invalid value to SysCacheIdentifier This commit tweaks the generation of the syscache IDs for the enum SysCacheIdentifier to now include an invalid value, with -1 assigned as value. The concept of an invalid syscache ID exists when handling lookups of a ObjectAddress, based on their set of properties in ObjectPropertyType. -1 is used for the case where an object type has no option for a syscache lookup. This has been found as independently useful while discussing a switch of SysCacheIdentifier to a typedef, as we already have places that want to know about the concept of an invalid value when dealing with ObjectAddresses. Reviewed-by: Andreas Karlsson Discussion: https://postgr.es/m/aZQRnmp9nVjtxAHS@paquier.xyz --- src/backend/catalog/aclchk.c | 2 +- src/backend/catalog/genbki.pl | 11 ++++- src/backend/catalog/objectaddress.c | 62 ++++++++++++++--------------- 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c index a431fc0926f..56060ca544e 100644 --- a/src/backend/catalog/aclchk.c +++ b/src/backend/catalog/aclchk.c @@ -4101,7 +4101,7 @@ object_ownercheck(Oid classid, Oid objectid, Oid roleid) classid = LargeObjectMetadataRelationId; cacheid = get_object_catcache_oid(classid); - if (cacheid != -1) + if (cacheid != SYSCACHEID_INVALID) { /* we can get the object's tuple from the syscache */ HeapTuple tuple; diff --git a/src/backend/catalog/genbki.pl b/src/backend/catalog/genbki.pl index b2c1b1c5733..975cc53435f 100644 --- a/src/backend/catalog/genbki.pl +++ b/src/backend/catalog/genbki.pl @@ -797,7 +797,7 @@ print $fk_info "};\n\n#endif\t\t\t\t\t\t\t/* SYSTEM_FK_INFO_H */\n"; print_boilerplate($syscache_ids_fh, "syscache_ids.h", "SysCache identifiers"); print $syscache_ids_fh "enum SysCacheIdentifier { -"; +\tSYSCACHEID_INVALID = -1,\n"; print_boilerplate($syscache_info_fh, "syscache_info.h", "SysCache definitions"); @@ -812,7 +812,14 @@ print $syscache_info_fh "static const struct cachedesc cacheinfo[] = {\n"; my $last_syscache; foreach my $syscache (sort keys %syscaches) { - print $syscache_ids_fh "\t$syscache,\n"; + if (not defined $last_syscache) + { + print $syscache_ids_fh "\t$syscache = 0,\n"; + } + else + { + print $syscache_ids_fh "\t$syscache,\n"; + } $last_syscache = $syscache; print $syscache_info_fh "\t[$syscache] = {\n"; diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c index 198caf641a5..33be6190909 100644 --- a/src/backend/catalog/objectaddress.c +++ b/src/backend/catalog/objectaddress.c @@ -135,8 +135,8 @@ static const ObjectPropertyType ObjectProperty[] = "access method operator", AccessMethodOperatorRelationId, AccessMethodOperatorOidIndexId, - -1, - -1, + SYSCACHEID_INVALID, + SYSCACHEID_INVALID, Anum_pg_amop_oid, InvalidAttrNumber, InvalidAttrNumber, @@ -149,8 +149,8 @@ static const ObjectPropertyType ObjectProperty[] = "access method procedure", AccessMethodProcedureRelationId, AccessMethodProcedureOidIndexId, - -1, - -1, + SYSCACHEID_INVALID, + SYSCACHEID_INVALID, Anum_pg_amproc_oid, InvalidAttrNumber, InvalidAttrNumber, @@ -163,8 +163,8 @@ static const ObjectPropertyType ObjectProperty[] = "cast", CastRelationId, CastOidIndexId, - -1, - -1, + SYSCACHEID_INVALID, + SYSCACHEID_INVALID, Anum_pg_cast_oid, InvalidAttrNumber, InvalidAttrNumber, @@ -178,7 +178,7 @@ static const ObjectPropertyType ObjectProperty[] = CollationRelationId, CollationOidIndexId, COLLOID, - -1, /* COLLNAMEENCNSP also takes encoding */ + SYSCACHEID_INVALID, /* COLLNAMEENCNSP also takes encoding */ Anum_pg_collation_oid, Anum_pg_collation_collname, Anum_pg_collation_collnamespace, @@ -192,7 +192,7 @@ static const ObjectPropertyType ObjectProperty[] = ConstraintRelationId, ConstraintOidIndexId, CONSTROID, - -1, + SYSCACHEID_INVALID, Anum_pg_constraint_oid, Anum_pg_constraint_conname, Anum_pg_constraint_connamespace, @@ -220,7 +220,7 @@ static const ObjectPropertyType ObjectProperty[] = DatabaseRelationId, DatabaseOidIndexId, DATABASEOID, - -1, + SYSCACHEID_INVALID, Anum_pg_database_oid, Anum_pg_database_datname, InvalidAttrNumber, @@ -233,8 +233,8 @@ static const ObjectPropertyType ObjectProperty[] = "default ACL", DefaultAclRelationId, DefaultAclOidIndexId, - -1, - -1, + SYSCACHEID_INVALID, + SYSCACHEID_INVALID, Anum_pg_default_acl_oid, InvalidAttrNumber, InvalidAttrNumber, @@ -247,8 +247,8 @@ static const ObjectPropertyType ObjectProperty[] = "extension", ExtensionRelationId, ExtensionOidIndexId, - -1, - -1, + SYSCACHEID_INVALID, + SYSCACHEID_INVALID, Anum_pg_extension_oid, Anum_pg_extension_extname, InvalidAttrNumber, /* extension doesn't belong to extnamespace */ @@ -290,7 +290,7 @@ static const ObjectPropertyType ObjectProperty[] = ProcedureRelationId, ProcedureOidIndexId, PROCOID, - -1, /* PROCNAMEARGSNSP also takes argument types */ + SYSCACHEID_INVALID, /* PROCNAMEARGSNSP also takes argument types */ Anum_pg_proc_oid, Anum_pg_proc_proname, Anum_pg_proc_pronamespace, @@ -317,8 +317,8 @@ static const ObjectPropertyType ObjectProperty[] = "large object metadata", LargeObjectMetadataRelationId, LargeObjectMetadataOidIndexId, - -1, - -1, + SYSCACHEID_INVALID, + SYSCACHEID_INVALID, Anum_pg_largeobject_metadata_oid, InvalidAttrNumber, InvalidAttrNumber, @@ -332,7 +332,7 @@ static const ObjectPropertyType ObjectProperty[] = OperatorClassRelationId, OpclassOidIndexId, CLAOID, - -1, /* CLAAMNAMENSP also takes opcmethod */ + SYSCACHEID_INVALID, /* CLAAMNAMENSP also takes opcmethod */ Anum_pg_opclass_oid, Anum_pg_opclass_opcname, Anum_pg_opclass_opcnamespace, @@ -346,7 +346,7 @@ static const ObjectPropertyType ObjectProperty[] = OperatorRelationId, OperatorOidIndexId, OPEROID, - -1, /* OPERNAMENSP also takes left and right type */ + SYSCACHEID_INVALID, /* OPERNAMENSP also takes left and right type */ Anum_pg_operator_oid, Anum_pg_operator_oprname, Anum_pg_operator_oprnamespace, @@ -360,7 +360,7 @@ static const ObjectPropertyType ObjectProperty[] = OperatorFamilyRelationId, OpfamilyOidIndexId, OPFAMILYOID, - -1, /* OPFAMILYAMNAMENSP also takes opfmethod */ + SYSCACHEID_INVALID, /* OPFAMILYAMNAMENSP also takes opfmethod */ Anum_pg_opfamily_oid, Anum_pg_opfamily_opfname, Anum_pg_opfamily_opfnamespace, @@ -387,8 +387,8 @@ static const ObjectPropertyType ObjectProperty[] = "role membership", AuthMemRelationId, AuthMemOidIndexId, - -1, - -1, + SYSCACHEID_INVALID, + SYSCACHEID_INVALID, Anum_pg_auth_members_oid, InvalidAttrNumber, InvalidAttrNumber, @@ -401,8 +401,8 @@ static const ObjectPropertyType ObjectProperty[] = "rule", RewriteRelationId, RewriteOidIndexId, - -1, - -1, + SYSCACHEID_INVALID, + SYSCACHEID_INVALID, Anum_pg_rewrite_oid, Anum_pg_rewrite_rulename, InvalidAttrNumber, @@ -444,7 +444,7 @@ static const ObjectPropertyType ObjectProperty[] = TableSpaceRelationId, TablespaceOidIndexId, TABLESPACEOID, - -1, + SYSCACHEID_INVALID, Anum_pg_tablespace_oid, Anum_pg_tablespace_spcname, InvalidAttrNumber, @@ -458,7 +458,7 @@ static const ObjectPropertyType ObjectProperty[] = TransformRelationId, TransformOidIndexId, TRFOID, - -1, + SYSCACHEID_INVALID, Anum_pg_transform_oid, InvalidAttrNumber, InvalidAttrNumber, @@ -471,8 +471,8 @@ static const ObjectPropertyType ObjectProperty[] = "trigger", TriggerRelationId, TriggerOidIndexId, - -1, - -1, + SYSCACHEID_INVALID, + SYSCACHEID_INVALID, Anum_pg_trigger_oid, Anum_pg_trigger_tgname, InvalidAttrNumber, @@ -485,8 +485,8 @@ static const ObjectPropertyType ObjectProperty[] = "policy", PolicyRelationId, PolicyOidIndexId, - -1, - -1, + SYSCACHEID_INVALID, + SYSCACHEID_INVALID, Anum_pg_policy_oid, Anum_pg_policy_polname, InvalidAttrNumber, @@ -626,7 +626,7 @@ static const ObjectPropertyType ObjectProperty[] = UserMappingRelationId, UserMappingOidIndexId, USERMAPPINGOID, - -1, + SYSCACHEID_INVALID, Anum_pg_user_mapping_oid, InvalidAttrNumber, InvalidAttrNumber, @@ -2583,7 +2583,7 @@ get_object_namespace(const ObjectAddress *address) /* Currently, we can only handle object types with system caches. */ cache = property->oid_catcache_id; - Assert(cache != -1); + Assert(cache != SYSCACHEID_INVALID); /* Fetch tuple from syscache and extract namespace attribute. */ tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));