Skip to content

Commit 2a990ab

Browse files
committed
Add missing ObjectIdGetDatum() in syscache lookup calls for Oids
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/ZLUhqsqQN1MOaxdw@paquier.xyz
1 parent 47556a0 commit 2a990ab

File tree

11 files changed

+22
-17
lines changed

11 files changed

+22
-17
lines changed

src/backend/catalog/index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,7 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId,
13301330
indcoloptions = (int2vector *) DatumGetPointer(colOptionDatum);
13311331

13321332
/* Fetch options of index if any */
1333-
classTuple = SearchSysCache1(RELOID, oldIndexId);
1333+
classTuple = SearchSysCache1(RELOID, ObjectIdGetDatum(oldIndexId));
13341334
if (!HeapTupleIsValid(classTuple))
13351335
elog(ERROR, "cache lookup failed for relation %u", oldIndexId);
13361336
optionDatum = SysCacheGetAttr(RELOID, classTuple,

src/backend/commands/alter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name)
295295
}
296296
else if (classId == SubscriptionRelationId)
297297
{
298-
if (SearchSysCacheExists2(SUBSCRIPTIONNAME, MyDatabaseId,
298+
if (SearchSysCacheExists2(SUBSCRIPTIONNAME,
299+
ObjectIdGetDatum(MyDatabaseId),
299300
CStringGetDatum(new_name)))
300301
report_name_conflict(classId, new_name);
301302

src/backend/commands/sequence.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,7 @@ sequence_options(Oid relid)
17181718
Form_pg_sequence pgsform;
17191719
List *options = NIL;
17201720

1721-
pgstuple = SearchSysCache1(SEQRELID, relid);
1721+
pgstuple = SearchSysCache1(SEQRELID, ObjectIdGetDatum(relid));
17221722
if (!HeapTupleIsValid(pgstuple))
17231723
elog(ERROR, "cache lookup failed for sequence %u", relid);
17241724
pgsform = (Form_pg_sequence) GETSTRUCT(pgstuple);
@@ -1766,7 +1766,7 @@ pg_sequence_parameters(PG_FUNCTION_ARGS)
17661766

17671767
memset(isnull, 0, sizeof(isnull));
17681768

1769-
pgstuple = SearchSysCache1(SEQRELID, relid);
1769+
pgstuple = SearchSysCache1(SEQRELID, ObjectIdGetDatum(relid));
17701770
if (!HeapTupleIsValid(pgstuple))
17711771
elog(ERROR, "cache lookup failed for sequence %u", relid);
17721772
pgsform = (Form_pg_sequence) GETSTRUCT(pgstuple);

src/backend/commands/tablecmds.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10147,7 +10147,7 @@ CloneFkReferenced(Relation parentRel, Relation partitionRel)
1014710147
Oid deleteTriggerOid,
1014810148
updateTriggerOid;
1014910149

10150-
tuple = SearchSysCache1(CONSTROID, constrOid);
10150+
tuple = SearchSysCache1(CONSTROID, ObjectIdGetDatum(constrOid));
1015110151
if (!HeapTupleIsValid(tuple))
1015210152
elog(ERROR, "cache lookup failed for constraint %u", constrOid);
1015310153
constrForm = (Form_pg_constraint) GETSTRUCT(tuple);
@@ -10353,7 +10353,7 @@ CloneFkReferencing(List **wqueue, Relation parentRel, Relation partRel)
1035310353
Oid insertTriggerOid,
1035410354
updateTriggerOid;
1035510355

10356-
tuple = SearchSysCache1(CONSTROID, parentConstrOid);
10356+
tuple = SearchSysCache1(CONSTROID, ObjectIdGetDatum(parentConstrOid));
1035710357
if (!HeapTupleIsValid(tuple))
1035810358
elog(ERROR, "cache lookup failed for constraint %u",
1035910359
parentConstrOid);
@@ -13723,7 +13723,7 @@ ATExecAlterColumnGenericOptions(Relation rel,
1372313723

1372413724
/* First, determine FDW validator associated to the foreign table. */
1372513725
ftrel = table_open(ForeignTableRelationId, AccessShareLock);
13726-
tuple = SearchSysCache1(FOREIGNTABLEREL, rel->rd_id);
13726+
tuple = SearchSysCache1(FOREIGNTABLEREL, ObjectIdGetDatum(rel->rd_id));
1372713727
if (!HeapTupleIsValid(tuple))
1372813728
ereport(ERROR,
1372913729
(errcode(ERRCODE_UNDEFINED_OBJECT),
@@ -16186,7 +16186,8 @@ ATExecGenericOptions(Relation rel, List *options)
1618616186

1618716187
ftrel = table_open(ForeignTableRelationId, RowExclusiveLock);
1618816188

16189-
tuple = SearchSysCacheCopy1(FOREIGNTABLEREL, rel->rd_id);
16189+
tuple = SearchSysCacheCopy1(FOREIGNTABLEREL,
16190+
ObjectIdGetDatum(rel->rd_id));
1619016191
if (!HeapTupleIsValid(tuple))
1619116192
ereport(ERROR,
1619216193
(errcode(ERRCODE_UNDEFINED_OBJECT),

src/backend/commands/user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1935,7 +1935,7 @@ AddRoleMems(Oid currentUserId, const char *rolename, Oid roleid,
19351935
HeapTuple mrtup;
19361936
Form_pg_authid mrform;
19371937

1938-
mrtup = SearchSysCache1(AUTHOID, memberid);
1938+
mrtup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(memberid));
19391939
if (!HeapTupleIsValid(mrtup))
19401940
elog(ERROR, "cache lookup failed for role %u", memberid);
19411941
mrform = (Form_pg_authid) GETSTRUCT(mrtup);

src/backend/partitioning/partbounds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4313,7 +4313,7 @@ get_qual_for_range(Relation parent, PartitionBoundSpec *spec,
43134313
Datum datum;
43144314
PartitionBoundSpec *bspec;
43154315

4316-
tuple = SearchSysCache1(RELOID, inhrelid);
4316+
tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(inhrelid));
43174317
if (!HeapTupleIsValid(tuple))
43184318
elog(ERROR, "cache lookup failed for relation %u", inhrelid);
43194319

src/backend/partitioning/partdesc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ RelationBuildPartitionDesc(Relation rel, bool omit_detached)
183183
PartitionBoundSpec *boundspec = NULL;
184184

185185
/* Try fetching the tuple from the catcache, for speed. */
186-
tuple = SearchSysCache1(RELOID, inhrelid);
186+
tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(inhrelid));
187187
if (HeapTupleIsValid(tuple))
188188
{
189189
Datum datum;

src/backend/utils/adt/acl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5334,13 +5334,13 @@ get_rolespec_tuple(const RoleSpec *role)
53345334

53355335
case ROLESPEC_CURRENT_ROLE:
53365336
case ROLESPEC_CURRENT_USER:
5337-
tuple = SearchSysCache1(AUTHOID, GetUserId());
5337+
tuple = SearchSysCache1(AUTHOID, ObjectIdGetDatum(GetUserId()));
53385338
if (!HeapTupleIsValid(tuple))
53395339
elog(ERROR, "cache lookup failed for role %u", GetUserId());
53405340
break;
53415341

53425342
case ROLESPEC_SESSION_USER:
5343-
tuple = SearchSysCache1(AUTHOID, GetSessionUserId());
5343+
tuple = SearchSysCache1(AUTHOID, ObjectIdGetDatum(GetSessionUserId()));
53445344
if (!HeapTupleIsValid(tuple))
53455345
elog(ERROR, "cache lookup failed for role %u", GetSessionUserId());
53465346
break;

src/backend/utils/adt/ruleutils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3283,7 +3283,7 @@ print_function_arguments(StringInfo buf, HeapTuple proctup,
32833283
HeapTuple aggtup;
32843284
Form_pg_aggregate agg;
32853285

3286-
aggtup = SearchSysCache1(AGGFNOID, proc->oid);
3286+
aggtup = SearchSysCache1(AGGFNOID, ObjectIdGetDatum(proc->oid));
32873287
if (!HeapTupleIsValid(aggtup))
32883288
elog(ERROR, "cache lookup failed for aggregate %u",
32893289
proc->oid);

src/backend/utils/cache/lsyscache.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,7 +2106,8 @@ get_transform_fromsql(Oid typid, Oid langid, List *trftypes)
21062106
if (!list_member_oid(trftypes, typid))
21072107
return InvalidOid;
21082108

2109-
tup = SearchSysCache2(TRFTYPELANG, typid, langid);
2109+
tup = SearchSysCache2(TRFTYPELANG, ObjectIdGetDatum(typid),
2110+
ObjectIdGetDatum(langid));
21102111
if (HeapTupleIsValid(tup))
21112112
{
21122113
Oid funcid;
@@ -2127,7 +2128,8 @@ get_transform_tosql(Oid typid, Oid langid, List *trftypes)
21272128
if (!list_member_oid(trftypes, typid))
21282129
return InvalidOid;
21292130

2130-
tup = SearchSysCache2(TRFTYPELANG, typid, langid);
2131+
tup = SearchSysCache2(TRFTYPELANG, ObjectIdGetDatum(typid),
2132+
ObjectIdGetDatum(langid));
21312133
if (HeapTupleIsValid(tup))
21322134
{
21332135
Oid funcid;

src/backend/utils/cache/partcache.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ generate_partition_qual(Relation rel)
365365
parent = relation_open(parentrelid, AccessShareLock);
366366

367367
/* Get pg_class.relpartbound */
368-
tuple = SearchSysCache1(RELOID, RelationGetRelid(rel));
368+
tuple = SearchSysCache1(RELOID,
369+
ObjectIdGetDatum(RelationGetRelid(rel)));
369370
if (!HeapTupleIsValid(tuple))
370371
elog(ERROR, "cache lookup failed for relation %u",
371372
RelationGetRelid(rel));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy