Commit 9691aa72 authored by Tom Lane's avatar Tom Lane

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 62148c35.
parent 62148c35
...@@ -164,7 +164,7 @@ index_get_partition(Relation partition, Oid indexId) ...@@ -164,7 +164,7 @@ index_get_partition(Relation partition, Oid indexId)
bool ispartition; bool ispartition;
tup = SearchSysCache1(RELOID, ObjectIdGetDatum(partIdx)); tup = SearchSysCache1(RELOID, ObjectIdGetDatum(partIdx));
if (!tup) if (!HeapTupleIsValid(tup))
elog(ERROR, "cache lookup failed for relation %u", partIdx); elog(ERROR, "cache lookup failed for relation %u", partIdx);
classForm = (Form_pg_class) GETSTRUCT(tup); classForm = (Form_pg_class) GETSTRUCT(tup);
ispartition = classForm->relispartition; ispartition = classForm->relispartition;
......
...@@ -130,7 +130,7 @@ pg_relation_is_publishable(PG_FUNCTION_ARGS) ...@@ -130,7 +130,7 @@ pg_relation_is_publishable(PG_FUNCTION_ARGS)
bool result; bool result;
tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));
if (!tuple) if (!HeapTupleIsValid(tuple))
PG_RETURN_NULL(); PG_RETURN_NULL();
result = is_publishable_class(relid, (Form_pg_class) GETSTRUCT(tuple)); result = is_publishable_class(relid, (Form_pg_class) GETSTRUCT(tuple));
ReleaseSysCache(tuple); ReleaseSysCache(tuple);
......
...@@ -1219,7 +1219,7 @@ DefineIndex(Oid relationId, ...@@ -1219,7 +1219,7 @@ DefineIndex(Oid relationId,
tup = SearchSysCache1(INDEXRELID, tup = SearchSysCache1(INDEXRELID,
ObjectIdGetDatum(indexRelationId)); ObjectIdGetDatum(indexRelationId));
if (!tup) if (!HeapTupleIsValid(tup))
elog(ERROR, "cache lookup failed for index %u", elog(ERROR, "cache lookup failed for index %u",
indexRelationId); indexRelationId);
newtup = heap_copytuple(tup); newtup = heap_copytuple(tup);
......
...@@ -1071,7 +1071,7 @@ assignOperTypes(OpFamilyMember *member, Oid amoid, Oid typeoid) ...@@ -1071,7 +1071,7 @@ assignOperTypes(OpFamilyMember *member, Oid amoid, Oid typeoid)
/* Fetch the operator definition */ /* Fetch the operator definition */
optup = SearchSysCache1(OPEROID, ObjectIdGetDatum(member->object)); optup = SearchSysCache1(OPEROID, ObjectIdGetDatum(member->object));
if (optup == NULL) if (!HeapTupleIsValid(optup))
elog(ERROR, "cache lookup failed for operator %u", member->object); elog(ERROR, "cache lookup failed for operator %u", member->object);
opform = (Form_pg_operator) GETSTRUCT(optup); opform = (Form_pg_operator) GETSTRUCT(optup);
...@@ -1137,7 +1137,7 @@ assignProcTypes(OpFamilyMember *member, Oid amoid, Oid typeoid) ...@@ -1137,7 +1137,7 @@ assignProcTypes(OpFamilyMember *member, Oid amoid, Oid typeoid)
/* Fetch the procedure definition */ /* Fetch the procedure definition */
proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(member->object)); proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(member->object));
if (proctup == NULL) if (!HeapTupleIsValid(proctup))
elog(ERROR, "cache lookup failed for function %u", member->object); elog(ERROR, "cache lookup failed for function %u", member->object);
procform = (Form_pg_proc) GETSTRUCT(proctup); procform = (Form_pg_proc) GETSTRUCT(proctup);
......
...@@ -407,7 +407,7 @@ AlterOperator(AlterOperatorStmt *stmt) ...@@ -407,7 +407,7 @@ AlterOperator(AlterOperatorStmt *stmt)
oprId = LookupOperWithArgs(stmt->opername, false); oprId = LookupOperWithArgs(stmt->opername, false);
catalog = table_open(OperatorRelationId, RowExclusiveLock); catalog = table_open(OperatorRelationId, RowExclusiveLock);
tup = SearchSysCacheCopy1(OPEROID, ObjectIdGetDatum(oprId)); tup = SearchSysCacheCopy1(OPEROID, ObjectIdGetDatum(oprId));
if (tup == NULL) if (!HeapTupleIsValid(tup))
elog(ERROR, "cache lookup failed for operator %u", oprId); elog(ERROR, "cache lookup failed for operator %u", oprId);
oprForm = (Form_pg_operator) GETSTRUCT(tup); oprForm = (Form_pg_operator) GETSTRUCT(tup);
......
...@@ -461,7 +461,7 @@ UpdateStatisticsForTypeChange(Oid statsOid, Oid relationOid, int attnum, ...@@ -461,7 +461,7 @@ UpdateStatisticsForTypeChange(Oid statsOid, Oid relationOid, int attnum,
bool replaces[Natts_pg_statistic_ext]; bool replaces[Natts_pg_statistic_ext];
oldtup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(statsOid)); oldtup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(statsOid));
if (!oldtup) if (!HeapTupleIsValid(oldtup))
elog(ERROR, "cache lookup failed for statistics object %u", statsOid); elog(ERROR, "cache lookup failed for statistics object %u", statsOid);
/* /*
......
...@@ -8606,7 +8606,7 @@ CloneFkReferencing(List **wqueue, Relation parentRel, Relation partRel) ...@@ -8606,7 +8606,7 @@ CloneFkReferencing(List **wqueue, Relation parentRel, Relation partRel)
ListCell *cell; ListCell *cell;
tuple = SearchSysCache1(CONSTROID, parentConstrOid); tuple = SearchSysCache1(CONSTROID, parentConstrOid);
if (!tuple) if (!HeapTupleIsValid(tuple))
elog(ERROR, "cache lookup failed for constraint %u", elog(ERROR, "cache lookup failed for constraint %u",
parentConstrOid); parentConstrOid);
constrForm = (Form_pg_constraint) GETSTRUCT(tuple); constrForm = (Form_pg_constraint) GETSTRUCT(tuple);
...@@ -8785,7 +8785,7 @@ tryAttachPartitionForeignKey(ForeignKeyCacheInfo *fk, ...@@ -8785,7 +8785,7 @@ tryAttachPartitionForeignKey(ForeignKeyCacheInfo *fk,
parentConstrTup = SearchSysCache1(CONSTROID, parentConstrTup = SearchSysCache1(CONSTROID,
ObjectIdGetDatum(parentConstrOid)); ObjectIdGetDatum(parentConstrOid));
if (!parentConstrTup) if (!HeapTupleIsValid(parentConstrTup))
elog(ERROR, "cache lookup failed for constraint %u", parentConstrOid); elog(ERROR, "cache lookup failed for constraint %u", parentConstrOid);
parentConstr = (Form_pg_constraint) GETSTRUCT(parentConstrTup); parentConstr = (Form_pg_constraint) GETSTRUCT(parentConstrTup);
...@@ -8816,9 +8816,8 @@ tryAttachPartitionForeignKey(ForeignKeyCacheInfo *fk, ...@@ -8816,9 +8816,8 @@ tryAttachPartitionForeignKey(ForeignKeyCacheInfo *fk,
*/ */
partcontup = SearchSysCache1(CONSTROID, partcontup = SearchSysCache1(CONSTROID,
ObjectIdGetDatum(fk->conoid)); ObjectIdGetDatum(fk->conoid));
if (!partcontup) if (!HeapTupleIsValid(partcontup))
elog(ERROR, "cache lookup failed for constraint %u", elog(ERROR, "cache lookup failed for constraint %u", fk->conoid);
fk->conoid);
partConstr = (Form_pg_constraint) GETSTRUCT(partcontup); partConstr = (Form_pg_constraint) GETSTRUCT(partcontup);
if (OidIsValid(partConstr->conparentid) || if (OidIsValid(partConstr->conparentid) ||
!partConstr->convalidated || !partConstr->convalidated ||
...@@ -16001,7 +16000,7 @@ ATExecDetachPartition(Relation rel, RangeVar *name) ...@@ -16001,7 +16000,7 @@ ATExecDetachPartition(Relation rel, RangeVar *name)
Constraint *fkconstraint; Constraint *fkconstraint;
contup = SearchSysCache1(CONSTROID, ObjectIdGetDatum(fk->conoid)); contup = SearchSysCache1(CONSTROID, ObjectIdGetDatum(fk->conoid));
if (!contup) if (!HeapTupleIsValid(contup))
elog(ERROR, "cache lookup failed for constraint %u", fk->conoid); elog(ERROR, "cache lookup failed for constraint %u", fk->conoid);
conform = (Form_pg_constraint) GETSTRUCT(contup); conform = (Form_pg_constraint) GETSTRUCT(contup);
...@@ -16346,9 +16345,8 @@ validatePartitionedIndex(Relation partedIdx, Relation partedTbl) ...@@ -16346,9 +16345,8 @@ validatePartitionedIndex(Relation partedIdx, Relation partedTbl)
indTup = SearchSysCache1(INDEXRELID, indTup = SearchSysCache1(INDEXRELID,
ObjectIdGetDatum(inhForm->inhrelid)); ObjectIdGetDatum(inhForm->inhrelid));
if (!indTup) if (!HeapTupleIsValid(indTup))
elog(ERROR, "cache lookup failed for index %u", elog(ERROR, "cache lookup failed for index %u", inhForm->inhrelid);
inhForm->inhrelid);
indexForm = (Form_pg_index) GETSTRUCT(indTup); indexForm = (Form_pg_index) GETSTRUCT(indTup);
if (indexForm->indisvalid) if (indexForm->indisvalid)
tuples += 1; tuples += 1;
......
...@@ -134,7 +134,7 @@ make_inh_translation_list(Relation oldrelation, Relation newrelation, ...@@ -134,7 +134,7 @@ make_inh_translation_list(Relation oldrelation, Relation newrelation,
HeapTuple newtup; HeapTuple newtup;
newtup = SearchSysCacheAttName(new_relid, attname); newtup = SearchSysCacheAttName(new_relid, attname);
if (!newtup) if (!HeapTupleIsValid(newtup))
elog(ERROR, "could not find inherited attribute \"%s\" of relation \"%s\"", elog(ERROR, "could not find inherited attribute \"%s\" of relation \"%s\"",
attname, RelationGetRelationName(newrelation)); attname, RelationGetRelationName(newrelation));
new_attno = ((Form_pg_attribute) GETSTRUCT(newtup))->attnum - 1; new_attno = ((Form_pg_attribute) GETSTRUCT(newtup))->attnum - 1;
......
...@@ -1312,7 +1312,7 @@ get_relation_statistics(RelOptInfo *rel, Relation relation) ...@@ -1312,7 +1312,7 @@ get_relation_statistics(RelOptInfo *rel, Relation relation)
int i; int i;
htup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(statOid)); htup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(statOid));
if (!htup) if (!HeapTupleIsValid(htup))
elog(ERROR, "cache lookup failed for statistics object %u", statOid); elog(ERROR, "cache lookup failed for statistics object %u", statOid);
staForm = (Form_pg_statistic_ext) GETSTRUCT(htup); staForm = (Form_pg_statistic_ext) GETSTRUCT(htup);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment