public inbox for [email protected]  
help / color / mirror / Atom feed
From: Michael Paquier <[email protected]>
To: Postgres hackers <[email protected]>
Subject: One-off with syscache ID in get_catalog_object_by_oid_extended()
Date: Wed, 18 Feb 2026 07:30:21 +0900
Message-ID: <[email protected]> (raw)

Hi all,

While reviewing the syscache code, I have bumped into the following
funny bit in objectaddress.c:
    if (oidCacheId > 0)
    {
        if (locktup)
            tuple = SearchSysCacheLockedCopy1(oidCacheId,
                                              ObjectIdGetDatum(objectId));
        else
            tuple = SearchSysCacheCopy1(oidCacheId,
                                        ObjectIdGetDatum(objectId));
        if (!HeapTupleIsValid(tuple))    /* should not happen */
            return NULL;
    }

This is wrong, because SysCacheIdentifier starts at 0.  This has no
consequence currently, because the first value in the enum is
AGGFNOID, something that we don't rely on for object type lookups.
Even if this code had the idea to use an ID of 0, the logic would just
get back to a systable lookup, that would still work, that's just less
efficient.

Simple patch attached, planned for a backpatch quickly as I am playing
with a different patch that reworks a bit this code.

Regards,
--
Michael

diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c
index 02af64b82c68..198caf641a5e 100644
--- a/src/backend/catalog/objectaddress.c
+++ b/src/backend/catalog/objectaddress.c
@@ -2808,7 +2808,7 @@ get_catalog_object_by_oid_extended(Relation catalog,
 	Oid			classId = RelationGetRelid(catalog);
 	int			oidCacheId = get_object_catcache_oid(classId);
 
-	if (oidCacheId > 0)
+	if (oidCacheId >= 0)
 	{
 		if (locktup)
 			tuple = SearchSysCacheLockedCopy1(oidCacheId,


Attachments:

  [text/plain] cacheid-oneoff.patch (503B, ../[email protected]/2-cacheid-oneoff.patch)
  download | inline diff:
diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c
index 02af64b82c68..198caf641a5e 100644
--- a/src/backend/catalog/objectaddress.c
+++ b/src/backend/catalog/objectaddress.c
@@ -2808,7 +2808,7 @@ get_catalog_object_by_oid_extended(Relation catalog,
 	Oid			classId = RelationGetRelid(catalog);
 	int			oidCacheId = get_object_catcache_oid(classId);
 
-	if (oidCacheId > 0)
+	if (oidCacheId >= 0)
 	{
 		if (locktup)
 			tuple = SearchSysCacheLockedCopy1(oidCacheId,


  [application/pgp-signature] signature.asc (833B, ../[email protected]/3-signature.asc)
  download

view thread (3+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: One-off with syscache ID in get_catalog_object_by_oid_extended()
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox