diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2019-05-05 13:10:07 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2019-05-05 13:10:07 -0400 |
commit | 000f557c3111add0e5aa28936ba8ad49ff896667 (patch) | |
tree | fcd1c4e473b57d28f1ba152cb08ac4fc67a18a92 | |
parent | 030ad0acfa5794c645a9a6093fdd3ed4d4f4788c (diff) | |
download | postgresql-000f557c3111add0e5aa28936ba8ad49ff896667.tar.gz postgresql-000f557c3111add0e5aa28936ba8ad49ff896667.zip |
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 62148c352.
-rw-r--r-- | src/backend/catalog/pg_publication.c | 2 | ||||
-rw-r--r-- | src/backend/commands/indexcmds.c | 2 | ||||
-rw-r--r-- | src/backend/commands/opclasscmds.c | 4 | ||||
-rw-r--r-- | src/backend/commands/operatorcmds.c | 2 | ||||
-rw-r--r-- | src/backend/commands/tablecmds.c | 11 | ||||
-rw-r--r-- | src/backend/optimizer/util/plancat.c | 2 |
6 files changed, 11 insertions, 12 deletions
diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index ec3bd1d22d2..6b02f7815e4 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -130,7 +130,7 @@ pg_relation_is_publishable(PG_FUNCTION_ARGS) bool result; tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); - if (!tuple) + if (!HeapTupleIsValid(tuple)) PG_RETURN_NULL(); result = is_publishable_class(relid, (Form_pg_class) GETSTRUCT(tuple)); ReleaseSysCache(tuple); diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 726f9476550..f00291da1b6 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1069,7 +1069,7 @@ DefineIndex(Oid relationId, tup = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(indexRelationId)); - if (!tup) + if (!HeapTupleIsValid(tup)) elog(ERROR, "cache lookup failed for index %u", indexRelationId); newtup = heap_copytuple(tup); diff --git a/src/backend/commands/opclasscmds.c b/src/backend/commands/opclasscmds.c index 3b5c90e3f41..6404188d02a 100644 --- a/src/backend/commands/opclasscmds.c +++ b/src/backend/commands/opclasscmds.c @@ -1057,7 +1057,7 @@ assignOperTypes(OpFamilyMember *member, Oid amoid, Oid typeoid) /* Fetch the operator definition */ optup = SearchSysCache1(OPEROID, ObjectIdGetDatum(member->object)); - if (optup == NULL) + if (!HeapTupleIsValid(optup)) elog(ERROR, "cache lookup failed for operator %u", member->object); opform = (Form_pg_operator) GETSTRUCT(optup); @@ -1123,7 +1123,7 @@ assignProcTypes(OpFamilyMember *member, Oid amoid, Oid typeoid) /* Fetch the procedure definition */ proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(member->object)); - if (proctup == NULL) + if (!HeapTupleIsValid(proctup)) elog(ERROR, "cache lookup failed for function %u", member->object); procform = (Form_pg_proc) GETSTRUCT(proctup); diff --git a/src/backend/commands/operatorcmds.c b/src/backend/commands/operatorcmds.c index 8fd8f7e8cff..01d67e0212f 100644 --- a/src/backend/commands/operatorcmds.c +++ b/src/backend/commands/operatorcmds.c @@ -407,7 +407,7 @@ AlterOperator(AlterOperatorStmt *stmt) oprId = LookupOperWithArgs(stmt->opername, false); catalog = heap_open(OperatorRelationId, RowExclusiveLock); tup = SearchSysCacheCopy1(OPEROID, ObjectIdGetDatum(oprId)); - if (tup == NULL) + if (!HeapTupleIsValid(tup)) elog(ERROR, "cache lookup failed for operator %u", oprId); oprForm = (Form_pg_operator) GETSTRUCT(tup); diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 6bba661724e..3cd899b1f98 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -7926,7 +7926,7 @@ CloneFkReferencing(Relation pg_constraint, Relation parentRel, int i; tuple = SearchSysCache1(CONSTROID, parentConstrOid); - if (!tuple) + if (!HeapTupleIsValid(tuple)) elog(ERROR, "cache lookup failed for constraint %u", parentConstrOid); constrForm = (Form_pg_constraint) GETSTRUCT(tuple); @@ -7995,7 +7995,7 @@ CloneFkReferencing(Relation pg_constraint, Relation parentRel, */ partcontup = SearchSysCache1(CONSTROID, ObjectIdGetDatum(fk->conoid)); - if (!partcontup) + if (!HeapTupleIsValid(partcontup)) elog(ERROR, "cache lookup failed for constraint %u", fk->conoid); partConstr = (Form_pg_constraint) GETSTRUCT(partcontup); @@ -15310,7 +15310,7 @@ ATExecDetachPartition(Relation rel, RangeVar *name) Constraint *fkconstraint; contup = SearchSysCache1(CONSTROID, ObjectIdGetDatum(fk->conoid)); - if (!contup) + if (!HeapTupleIsValid(contup)) elog(ERROR, "cache lookup failed for constraint %u", fk->conoid); conform = (Form_pg_constraint) GETSTRUCT(contup); @@ -15650,9 +15650,8 @@ validatePartitionedIndex(Relation partedIdx, Relation partedTbl) indTup = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(inhForm->inhrelid)); - if (!indTup) - elog(ERROR, "cache lookup failed for index %u", - inhForm->inhrelid); + if (!HeapTupleIsValid(indTup)) + elog(ERROR, "cache lookup failed for index %u", inhForm->inhrelid); indexForm = (Form_pg_index) GETSTRUCT(indTup); if (IndexIsValid(indexForm)) tuples += 1; diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index 223131a9e5c..d99d1393fb4 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -1335,7 +1335,7 @@ get_relation_statistics(RelOptInfo *rel, Relation relation) int i; htup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(statOid)); - if (!htup) + if (!HeapTupleIsValid(htup)) elog(ERROR, "cache lookup failed for statistics object %u", statOid); staForm = (Form_pg_statistic_ext) GETSTRUCT(htup); |