]> granicus.if.org Git - postgresql/commitdiff
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/pg_publication.c
src/backend/commands/indexcmds.c
src/backend/commands/opclasscmds.c
src/backend/commands/operatorcmds.c
src/backend/commands/tablecmds.c
src/backend/optimizer/util/plancat.c

index ec3bd1d22d22a399d54001d2a1d7ee3087f13bfc..6b02f7815e4e14b7c76d1ae459b2393047b557f5 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 726f947655071e95fb4b123b8003207e0567be3b..f00291da1b60ef636af77f3fe921df2790d30a4d 100644 (file)
@@ -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);
index 3b5c90e3f41ffe896672e16c874c17cbfb3d04e7..6404188d02adb53a3555b98479dd068ec2493ee2 100644 (file)
@@ -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);
 
index 8fd8f7e8cffc6065ef17ff978f584836d6d81f04..01d67e0212f339ddf5cfdef470c116b3ad3e52dd 100644 (file)
@@ -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);
 
index 6bba661724e9e320e817ad0bf70eb30548c604de..3cd899b1f98bce2a7dc614de32e67e99d9f39f80 100644 (file)
@@ -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;
index 223131a9e5c37bcb819aa7f632a103f397104ecf..d99d1393fb46327000636917df9444f88ece692b 100644 (file)
@@ -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);