Add missing ObjectIdGetDatum() in syscache lookup calls for Oids
authorMichael Paquier <[email protected]>
Thu, 20 Jul 2023 06:18:25 +0000 (15:18 +0900)
committerMichael Paquier <[email protected]>
Thu, 20 Jul 2023 06:18:25 +0000 (15:18 +0900)
Based on how postgres.h foes the Oid <-> Datum conversion, there is no
existing bugs but let's be consistent.  17 spots have been noticed as
incorrectly passing down Oids rather than Datums.  Aleksander got one,
Zhang two and I the rest.

Author: Michael Paquier, Aleksander Alekseev, Zhang Mingli
Discussion: https://postgr.es/m/[email protected]

src/backend/catalog/index.c
src/backend/commands/alter.c
src/backend/commands/sequence.c
src/backend/commands/tablecmds.c
src/backend/commands/user.c
src/backend/partitioning/partbounds.c
src/backend/partitioning/partdesc.c
src/backend/utils/adt/acl.c
src/backend/utils/adt/ruleutils.c
src/backend/utils/cache/lsyscache.c
src/backend/utils/cache/partcache.c

index 67b743e25146093f526eb16fadcde1cd5a03c176..eb2b8d84c334a6d8e6244e4b08f90a8414fa81ff 100644 (file)
@@ -1330,7 +1330,7 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId,
    indcoloptions = (int2vector *) DatumGetPointer(colOptionDatum);
 
    /* Fetch options of index if any */
-   classTuple = SearchSysCache1(RELOID, oldIndexId);
+   classTuple = SearchSysCache1(RELOID, ObjectIdGetDatum(oldIndexId));
    if (!HeapTupleIsValid(classTuple))
        elog(ERROR, "cache lookup failed for relation %u", oldIndexId);
    optionDatum = SysCacheGetAttr(RELOID, classTuple,
index d64929df558e4312b236ff2981039f3d962ea2b3..ff8d003876f84bb2def66efaa014bb40e2ca76f0 100644 (file)
@@ -295,7 +295,8 @@ AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name)
    }
    else if (classId == SubscriptionRelationId)
    {
-       if (SearchSysCacheExists2(SUBSCRIPTIONNAME, MyDatabaseId,
+       if (SearchSysCacheExists2(SUBSCRIPTIONNAME,
+                                 ObjectIdGetDatum(MyDatabaseId),
                                  CStringGetDatum(new_name)))
            report_name_conflict(classId, new_name);
 
index ef014496782ad55cb3633820a266c994ba1e46f9..fc4f77e787e7aecc578519df339669afc803d161 100644 (file)
@@ -1718,7 +1718,7 @@ sequence_options(Oid relid)
    Form_pg_sequence pgsform;
    List       *options = NIL;
 
-   pgstuple = SearchSysCache1(SEQRELID, relid);
+   pgstuple = SearchSysCache1(SEQRELID, ObjectIdGetDatum(relid));
    if (!HeapTupleIsValid(pgstuple))
        elog(ERROR, "cache lookup failed for sequence %u", relid);
    pgsform = (Form_pg_sequence) GETSTRUCT(pgstuple);
@@ -1766,7 +1766,7 @@ pg_sequence_parameters(PG_FUNCTION_ARGS)
 
    memset(isnull, 0, sizeof(isnull));
 
-   pgstuple = SearchSysCache1(SEQRELID, relid);
+   pgstuple = SearchSysCache1(SEQRELID, ObjectIdGetDatum(relid));
    if (!HeapTupleIsValid(pgstuple))
        elog(ERROR, "cache lookup failed for sequence %u", relid);
    pgsform = (Form_pg_sequence) GETSTRUCT(pgstuple);
index 4dc029f91f1cc621a37bbaf0f06520629bc9dcd9..727f15175072963f9ea8c02a392a29ac059e8956 100644 (file)
@@ -10147,7 +10147,7 @@ CloneFkReferenced(Relation parentRel, Relation partitionRel)
        Oid         deleteTriggerOid,
                    updateTriggerOid;
 
-       tuple = SearchSysCache1(CONSTROID, constrOid);
+       tuple = SearchSysCache1(CONSTROID, ObjectIdGetDatum(constrOid));
        if (!HeapTupleIsValid(tuple))
            elog(ERROR, "cache lookup failed for constraint %u", constrOid);
        constrForm = (Form_pg_constraint) GETSTRUCT(tuple);
@@ -10353,7 +10353,7 @@ CloneFkReferencing(List **wqueue, Relation parentRel, Relation partRel)
        Oid         insertTriggerOid,
                    updateTriggerOid;
 
-       tuple = SearchSysCache1(CONSTROID, parentConstrOid);
+       tuple = SearchSysCache1(CONSTROID, ObjectIdGetDatum(parentConstrOid));
        if (!HeapTupleIsValid(tuple))
            elog(ERROR, "cache lookup failed for constraint %u",
                 parentConstrOid);
@@ -13723,7 +13723,7 @@ ATExecAlterColumnGenericOptions(Relation rel,
 
    /* First, determine FDW validator associated to the foreign table. */
    ftrel = table_open(ForeignTableRelationId, AccessShareLock);
-   tuple = SearchSysCache1(FOREIGNTABLEREL, rel->rd_id);
+   tuple = SearchSysCache1(FOREIGNTABLEREL, ObjectIdGetDatum(rel->rd_id));
    if (!HeapTupleIsValid(tuple))
        ereport(ERROR,
                (errcode(ERRCODE_UNDEFINED_OBJECT),
@@ -16186,7 +16186,8 @@ ATExecGenericOptions(Relation rel, List *options)
 
    ftrel = table_open(ForeignTableRelationId, RowExclusiveLock);
 
-   tuple = SearchSysCacheCopy1(FOREIGNTABLEREL, rel->rd_id);
+   tuple = SearchSysCacheCopy1(FOREIGNTABLEREL,
+                               ObjectIdGetDatum(rel->rd_id));
    if (!HeapTupleIsValid(tuple))
        ereport(ERROR,
                (errcode(ERRCODE_UNDEFINED_OBJECT),
index 6b42d4fc34a7315c0f74bb042f2eb5386367d489..ce77a055e58585ef5e9cd139d421bdb0f8deb368 100644 (file)
@@ -1935,7 +1935,7 @@ AddRoleMems(Oid currentUserId, const char *rolename, Oid roleid,
                HeapTuple   mrtup;
                Form_pg_authid mrform;
 
-               mrtup = SearchSysCache1(AUTHOID, memberid);
+               mrtup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(memberid));
                if (!HeapTupleIsValid(mrtup))
                    elog(ERROR, "cache lookup failed for role %u", memberid);
                mrform = (Form_pg_authid) GETSTRUCT(mrtup);
index 7c5d9110fb09d857d946db1ca142c1752d40aa48..5436cc302d1bae83b12604696d0f57fee9e8d9cd 100644 (file)
@@ -4313,7 +4313,7 @@ get_qual_for_range(Relation parent, PartitionBoundSpec *spec,
            Datum       datum;
            PartitionBoundSpec *bspec;
 
-           tuple = SearchSysCache1(RELOID, inhrelid);
+           tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(inhrelid));
            if (!HeapTupleIsValid(tuple))
                elog(ERROR, "cache lookup failed for relation %u", inhrelid);
 
index 7a2b5e57ff428d0e3eb48bac37e05796c1895ceb..65f3d5a5e6e7443b2baa615054757912fc8ae803 100644 (file)
@@ -183,7 +183,7 @@ RelationBuildPartitionDesc(Relation rel, bool omit_detached)
        PartitionBoundSpec *boundspec = NULL;
 
        /* Try fetching the tuple from the catcache, for speed. */
-       tuple = SearchSysCache1(RELOID, inhrelid);
+       tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(inhrelid));
        if (HeapTupleIsValid(tuple))
        {
            Datum       datum;
index 883e09393a497029742b6981efcab25e7f640fbc..27eabb80abcbd0334bbbeedb709610aefd3d4393 100644 (file)
@@ -5334,13 +5334,13 @@ get_rolespec_tuple(const RoleSpec *role)
 
        case ROLESPEC_CURRENT_ROLE:
        case ROLESPEC_CURRENT_USER:
-           tuple = SearchSysCache1(AUTHOID, GetUserId());
+           tuple = SearchSysCache1(AUTHOID, ObjectIdGetDatum(GetUserId()));
            if (!HeapTupleIsValid(tuple))
                elog(ERROR, "cache lookup failed for role %u", GetUserId());
            break;
 
        case ROLESPEC_SESSION_USER:
-           tuple = SearchSysCache1(AUTHOID, GetSessionUserId());
+           tuple = SearchSysCache1(AUTHOID, ObjectIdGetDatum(GetSessionUserId()));
            if (!HeapTupleIsValid(tuple))
                elog(ERROR, "cache lookup failed for role %u", GetSessionUserId());
            break;
index d3a973d86b761db4f0a1d478396a7340b581a091..fcb2f45f623cba335172676007f50938e1417d57 100644 (file)
@@ -3283,7 +3283,7 @@ print_function_arguments(StringInfo buf, HeapTuple proctup,
        HeapTuple   aggtup;
        Form_pg_aggregate agg;
 
-       aggtup = SearchSysCache1(AGGFNOID, proc->oid);
+       aggtup = SearchSysCache1(AGGFNOID, ObjectIdGetDatum(proc->oid));
        if (!HeapTupleIsValid(aggtup))
            elog(ERROR, "cache lookup failed for aggregate %u",
                 proc->oid);
index 2c01a86c292eace7a87ee56c9159e6046cdc7a32..fc6d267e44c72a0d23efb9317b143fc4c388f827 100644 (file)
@@ -2106,7 +2106,8 @@ get_transform_fromsql(Oid typid, Oid langid, List *trftypes)
    if (!list_member_oid(trftypes, typid))
        return InvalidOid;
 
-   tup = SearchSysCache2(TRFTYPELANG, typid, langid);
+   tup = SearchSysCache2(TRFTYPELANG, ObjectIdGetDatum(typid),
+                         ObjectIdGetDatum(langid));
    if (HeapTupleIsValid(tup))
    {
        Oid         funcid;
@@ -2127,7 +2128,8 @@ get_transform_tosql(Oid typid, Oid langid, List *trftypes)
    if (!list_member_oid(trftypes, typid))
        return InvalidOid;
 
-   tup = SearchSysCache2(TRFTYPELANG, typid, langid);
+   tup = SearchSysCache2(TRFTYPELANG, ObjectIdGetDatum(typid),
+                         ObjectIdGetDatum(langid));
    if (HeapTupleIsValid(tup))
    {
        Oid         funcid;
index 5f3516ad0c2459c687f87175c6592425e7ce5af5..c6c0d5a00f65bf38b2e44d8312e2febec9269bc6 100644 (file)
@@ -365,7 +365,8 @@ generate_partition_qual(Relation rel)
    parent = relation_open(parentrelid, AccessShareLock);
 
    /* Get pg_class.relpartbound */
-   tuple = SearchSysCache1(RELOID, RelationGetRelid(rel));
+   tuple = SearchSysCache1(RELOID,
+                           ObjectIdGetDatum(RelationGetRelid(rel)));
    if (!HeapTupleIsValid(tuple))
        elog(ERROR, "cache lookup failed for relation %u",
             RelationGetRelid(rel));