Fix style violations in syscache lookups.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 5 May 2019 17:10:07 +0000 (13:10 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 5 May 2019 17:10:07 +0000 (13:10 -0400)
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.

src/backend/catalog/partition.c
src/backend/catalog/pg_publication.c
src/backend/commands/indexcmds.c
src/backend/commands/opclasscmds.c
src/backend/commands/operatorcmds.c
src/backend/commands/statscmds.c
src/backend/commands/tablecmds.c
src/backend/optimizer/util/appendinfo.c
src/backend/optimizer/util/plancat.c

index 8ea7a62418f3e574d64cab26cdaf174e93bdd2d8..da98c54391bcebcfb0fbe03af1d659285d3088f8 100644 (file)
@@ -164,7 +164,7 @@ index_get_partition(Relation partition, Oid indexId)
                bool            ispartition;
 
                tup = SearchSysCache1(RELOID, ObjectIdGetDatum(partIdx));
-               if (!tup)
+               if (!HeapTupleIsValid(tup))
                        elog(ERROR, "cache lookup failed for relation %u", partIdx);
                classForm = (Form_pg_class) GETSTRUCT(tup);
                ispartition = classForm->relispartition;
index bbf217393634c6eac7a18d2286172f402d3f5eb5..bda7a3e92b031f65b3ad520763690cf56ca61d86 100644 (file)
@@ -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);
index 26f3b2cd7a43e3c6d9f4213b2c3a70ac4a3fa880..663407c65d33f1e66374c4978f3d0beb8308564a 100644 (file)
@@ -1219,7 +1219,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);
index 5d73848a8b9b7ce4443524966d5a0bce48f3967c..b8c7b9657f7a67aaef223d6d646fa3aa529f69d7 100644 (file)
@@ -1071,7 +1071,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);
 
@@ -1137,7 +1137,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);
 
index 7b98e4b910cf7e4dcb92cf1b13c746a476552053..17f54410a005efbd0efb4a434e5d995f22042a65 100644 (file)
@@ -407,7 +407,7 @@ AlterOperator(AlterOperatorStmt *stmt)
        oprId = LookupOperWithArgs(stmt->opername, false);
        catalog = table_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);
 
index 790593b1ab3d611b5ce3a9559e2d59f8522a0402..a191916d0324450c314a7d2c424750abb35ad976 100644 (file)
@@ -461,7 +461,7 @@ UpdateStatisticsForTypeChange(Oid statsOid, Oid relationOid, int attnum,
        bool            replaces[Natts_pg_statistic_ext];
 
        oldtup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(statsOid));
-       if (!oldtup)
+       if (!HeapTupleIsValid(oldtup))
                elog(ERROR, "cache lookup failed for statistics object %u", statsOid);
 
        /*
index f6c9cf3b0ec96d9a52849a7338666cb851eab4eb..8e4743d11015f6a6837d35376f1c9dc9238d4512 100644 (file)
@@ -8606,7 +8606,7 @@ CloneFkReferencing(List **wqueue, Relation parentRel, Relation partRel)
                ListCell   *cell;
 
                tuple = SearchSysCache1(CONSTROID, parentConstrOid);
-               if (!tuple)
+               if (!HeapTupleIsValid(tuple))
                        elog(ERROR, "cache lookup failed for constraint %u",
                                 parentConstrOid);
                constrForm = (Form_pg_constraint) GETSTRUCT(tuple);
@@ -8785,7 +8785,7 @@ tryAttachPartitionForeignKey(ForeignKeyCacheInfo *fk,
 
        parentConstrTup = SearchSysCache1(CONSTROID,
                                                                          ObjectIdGetDatum(parentConstrOid));
-       if (!parentConstrTup)
+       if (!HeapTupleIsValid(parentConstrTup))
                elog(ERROR, "cache lookup failed for constraint %u", parentConstrOid);
        parentConstr = (Form_pg_constraint) GETSTRUCT(parentConstrTup);
 
@@ -8816,9 +8816,8 @@ tryAttachPartitionForeignKey(ForeignKeyCacheInfo *fk,
         */
        partcontup = SearchSysCache1(CONSTROID,
                                                                 ObjectIdGetDatum(fk->conoid));
-       if (!partcontup)
-               elog(ERROR, "cache lookup failed for constraint %u",
-                        fk->conoid);
+       if (!HeapTupleIsValid(partcontup))
+               elog(ERROR, "cache lookup failed for constraint %u", fk->conoid);
        partConstr = (Form_pg_constraint) GETSTRUCT(partcontup);
        if (OidIsValid(partConstr->conparentid) ||
                !partConstr->convalidated ||
@@ -16001,7 +16000,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);
 
@@ -16346,9 +16345,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 (indexForm->indisvalid)
                        tuples += 1;
index ca6622ece9b86dfbc725e94e04201e207b4c583a..ba955290b10e316579855071e9cf266750f55620 100644 (file)
@@ -134,7 +134,7 @@ make_inh_translation_list(Relation oldrelation, Relation newrelation,
                        HeapTuple       newtup;
 
                        newtup = SearchSysCacheAttName(new_relid, attname);
-                       if (!newtup)
+                       if (!HeapTupleIsValid(newtup))
                                elog(ERROR, "could not find inherited attribute \"%s\" of relation \"%s\"",
                                         attname, RelationGetRelationName(newrelation));
                        new_attno = ((Form_pg_attribute) GETSTRUCT(newtup))->attnum - 1;
index 3215c299ce46814f136aa728a21f7d7818bb0160..80441de65e6dee20f22a205702fd9d16de1a53cc 100644 (file)
@@ -1312,7 +1312,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);