Skip to content

Commit 000f557

Browse files
committed
Fix style violations in syscache lookups.
Project style is to check the success of SearchSysCacheN and friends by applying HeapTupleIsValid to the result. A tiny minority of calls creatively did it differently. Bring them into line with the rest. This is just cosmetic, since HeapTupleIsValid is indeed just a null check at the moment ... but that may not be true forever, and in any case it puts a mental burden on readers who may wonder why these call sites are not like the rest. Back-patch to v11 just to keep the branches in sync. (The bulk of these errors seem to have originated in v11 or v12, though a few are old.) Per searching to see if anyplace else had made the same error repaired in 62148c3.
1 parent 030ad0a commit 000f557

File tree

6 files changed

+11
-12
lines changed

6 files changed

+11
-12
lines changed

src/backend/catalog/pg_publication.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pg_relation_is_publishable(PG_FUNCTION_ARGS)
130130
bool result;
131131

132132
tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));
133-
if (!tuple)
133+
if (!HeapTupleIsValid(tuple))
134134
PG_RETURN_NULL();
135135
result = is_publishable_class(relid, (Form_pg_class) GETSTRUCT(tuple));
136136
ReleaseSysCache(tuple);

src/backend/commands/indexcmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ DefineIndex(Oid relationId,
10691069

10701070
tup = SearchSysCache1(INDEXRELID,
10711071
ObjectIdGetDatum(indexRelationId));
1072-
if (!tup)
1072+
if (!HeapTupleIsValid(tup))
10731073
elog(ERROR, "cache lookup failed for index %u",
10741074
indexRelationId);
10751075
newtup = heap_copytuple(tup);

src/backend/commands/opclasscmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ assignOperTypes(OpFamilyMember *member, Oid amoid, Oid typeoid)
10571057

10581058
/* Fetch the operator definition */
10591059
optup = SearchSysCache1(OPEROID, ObjectIdGetDatum(member->object));
1060-
if (optup == NULL)
1060+
if (!HeapTupleIsValid(optup))
10611061
elog(ERROR, "cache lookup failed for operator %u", member->object);
10621062
opform = (Form_pg_operator) GETSTRUCT(optup);
10631063

@@ -1123,7 +1123,7 @@ assignProcTypes(OpFamilyMember *member, Oid amoid, Oid typeoid)
11231123

11241124
/* Fetch the procedure definition */
11251125
proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(member->object));
1126-
if (proctup == NULL)
1126+
if (!HeapTupleIsValid(proctup))
11271127
elog(ERROR, "cache lookup failed for function %u", member->object);
11281128
procform = (Form_pg_proc) GETSTRUCT(proctup);
11291129

src/backend/commands/operatorcmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ AlterOperator(AlterOperatorStmt *stmt)
407407
oprId = LookupOperWithArgs(stmt->opername, false);
408408
catalog = heap_open(OperatorRelationId, RowExclusiveLock);
409409
tup = SearchSysCacheCopy1(OPEROID, ObjectIdGetDatum(oprId));
410-
if (tup == NULL)
410+
if (!HeapTupleIsValid(tup))
411411
elog(ERROR, "cache lookup failed for operator %u", oprId);
412412
oprForm = (Form_pg_operator) GETSTRUCT(tup);
413413

src/backend/commands/tablecmds.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7926,7 +7926,7 @@ CloneFkReferencing(Relation pg_constraint, Relation parentRel,
79267926
int i;
79277927

79287928
tuple = SearchSysCache1(CONSTROID, parentConstrOid);
7929-
if (!tuple)
7929+
if (!HeapTupleIsValid(tuple))
79307930
elog(ERROR, "cache lookup failed for constraint %u",
79317931
parentConstrOid);
79327932
constrForm = (Form_pg_constraint) GETSTRUCT(tuple);
@@ -7995,7 +7995,7 @@ CloneFkReferencing(Relation pg_constraint, Relation parentRel,
79957995
*/
79967996
partcontup = SearchSysCache1(CONSTROID,
79977997
ObjectIdGetDatum(fk->conoid));
7998-
if (!partcontup)
7998+
if (!HeapTupleIsValid(partcontup))
79997999
elog(ERROR, "cache lookup failed for constraint %u",
80008000
fk->conoid);
80018001
partConstr = (Form_pg_constraint) GETSTRUCT(partcontup);
@@ -15310,7 +15310,7 @@ ATExecDetachPartition(Relation rel, RangeVar *name)
1531015310
Constraint *fkconstraint;
1531115311

1531215312
contup = SearchSysCache1(CONSTROID, ObjectIdGetDatum(fk->conoid));
15313-
if (!contup)
15313+
if (!HeapTupleIsValid(contup))
1531415314
elog(ERROR, "cache lookup failed for constraint %u", fk->conoid);
1531515315
conform = (Form_pg_constraint) GETSTRUCT(contup);
1531615316

@@ -15650,9 +15650,8 @@ validatePartitionedIndex(Relation partedIdx, Relation partedTbl)
1565015650

1565115651
indTup = SearchSysCache1(INDEXRELID,
1565215652
ObjectIdGetDatum(inhForm->inhrelid));
15653-
if (!indTup)
15654-
elog(ERROR, "cache lookup failed for index %u",
15655-
inhForm->inhrelid);
15653+
if (!HeapTupleIsValid(indTup))
15654+
elog(ERROR, "cache lookup failed for index %u", inhForm->inhrelid);
1565615655
indexForm = (Form_pg_index) GETSTRUCT(indTup);
1565715656
if (IndexIsValid(indexForm))
1565815657
tuples += 1;

src/backend/optimizer/util/plancat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,7 @@ get_relation_statistics(RelOptInfo *rel, Relation relation)
13351335
int i;
13361336

13371337
htup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(statOid));
1338-
if (!htup)
1338+
if (!HeapTupleIsValid(htup))
13391339
elog(ERROR, "cache lookup failed for statistics object %u", statOid);
13401340
staForm = (Form_pg_statistic_ext) GETSTRUCT(htup);
13411341

0 commit comments

Comments
 (0)