Add SysCacheGetAttrNotNull for guaranteed not-null attrs
authorDaniel Gustafsson <[email protected]>
Sat, 25 Mar 2023 21:49:33 +0000 (22:49 +0100)
committerDaniel Gustafsson <[email protected]>
Sat, 25 Mar 2023 21:49:33 +0000 (22:49 +0100)
When extracting an attr from a cached tuple in the syscache with
SysCacheGetAttr the isnull parameter must be checked in case the
attr cannot be NULL.  For cases when this is known beforehand, a
wrapper is introduced which perform the errorhandling internally
on behalf of the caller, invoking an elog in case of a NULL attr.

Reviewed-by: Tom Lane <[email protected]>
Reviewed-by: Peter Eisentraut <[email protected]>
Reviewed-by: David Rowley <[email protected]>
Discussion: https://postgr.es/m/AD76405E-DB45-46B6-941F-17B1EB3A9076@yesql.se

38 files changed:
src/backend/access/brin/brin_inclusion.c
src/backend/access/brin/brin_minmax.c
src/backend/access/brin/brin_minmax_multi.c
src/backend/access/index/indexam.c
src/backend/catalog/aclchk.c
src/backend/catalog/index.c
src/backend/catalog/objectaddress.c
src/backend/catalog/pg_constraint.c
src/backend/catalog/pg_proc.c
src/backend/catalog/pg_subscription.c
src/backend/commands/collationcmds.c
src/backend/commands/dbcommands.c
src/backend/commands/indexcmds.c
src/backend/commands/matview.c
src/backend/commands/subscriptioncmds.c
src/backend/commands/tablecmds.c
src/backend/commands/typecmds.c
src/backend/executor/execReplication.c
src/backend/executor/functions.c
src/backend/optimizer/util/clauses.c
src/backend/parser/parse_func.c
src/backend/parser/parse_utilcmd.c
src/backend/partitioning/partbounds.c
src/backend/statistics/extended_stats.c
src/backend/utils/adt/amutils.c
src/backend/utils/adt/pg_locale.c
src/backend/utils/adt/ruleutils.c
src/backend/utils/cache/lsyscache.c
src/backend/utils/cache/partcache.c
src/backend/utils/cache/syscache.c
src/backend/utils/fmgr/fmgr.c
src/backend/utils/fmgr/funcapi.c
src/backend/utils/init/postinit.c
src/include/utils/syscache.h
src/pl/plperl/plperl.c
src/pl/plpgsql/src/pl_comp.c
src/pl/plpython/plpy_procedure.c
src/pl/tcl/pltcl.c

index 248116c1494426097129a123fb1fc8756fd56984..02f4d0ae76ec77639180c95522936e6732618d5c 100644 (file)
@@ -630,7 +630,6 @@ inclusion_get_strategy_procinfo(BrinDesc *bdesc, uint16 attno, Oid subtype,
                HeapTuple       tuple;
                Oid                     opfamily,
                                        oprid;
-               bool            isNull;
 
                opfamily = bdesc->bd_index->rd_opfamily[attno - 1];
                attr = TupleDescAttr(bdesc->bd_tupdesc, attno - 1);
@@ -643,10 +642,10 @@ inclusion_get_strategy_procinfo(BrinDesc *bdesc, uint16 attno, Oid subtype,
                        elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
                                 strategynum, attr->atttypid, subtype, opfamily);
 
-               oprid = DatumGetObjectId(SysCacheGetAttr(AMOPSTRATEGY, tuple,
-                                                                                                Anum_pg_amop_amopopr, &isNull));
+               oprid = DatumGetObjectId(SysCacheGetAttrNotNull(AMOPSTRATEGY, tuple,
+                                                                                                               Anum_pg_amop_amopopr));
                ReleaseSysCache(tuple);
-               Assert(!isNull && RegProcedureIsValid(oprid));
+               Assert(RegProcedureIsValid(oprid));
 
                fmgr_info_cxt(get_opcode(oprid),
                                          &opaque->strategy_procinfos[strategynum - 1],
index 2431591be65cf5538f1f2342b4a1ad02a88c08f8..8229493c84acb36d4e7eccfd65617d40178fe254 100644 (file)
@@ -290,7 +290,6 @@ minmax_get_strategy_procinfo(BrinDesc *bdesc, uint16 attno, Oid subtype,
                HeapTuple       tuple;
                Oid                     opfamily,
                                        oprid;
-               bool            isNull;
 
                opfamily = bdesc->bd_index->rd_opfamily[attno - 1];
                attr = TupleDescAttr(bdesc->bd_tupdesc, attno - 1);
@@ -303,10 +302,10 @@ minmax_get_strategy_procinfo(BrinDesc *bdesc, uint16 attno, Oid subtype,
                        elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
                                 strategynum, attr->atttypid, subtype, opfamily);
 
-               oprid = DatumGetObjectId(SysCacheGetAttr(AMOPSTRATEGY, tuple,
-                                                                                                Anum_pg_amop_amopopr, &isNull));
+               oprid = DatumGetObjectId(SysCacheGetAttrNotNull(AMOPSTRATEGY, tuple,
+                                                                                                               Anum_pg_amop_amopopr));
                ReleaseSysCache(tuple);
-               Assert(!isNull && RegProcedureIsValid(oprid));
+               Assert(RegProcedureIsValid(oprid));
 
                fmgr_info_cxt(get_opcode(oprid),
                                          &opaque->strategy_procinfos[strategynum - 1],
index cdf78cdecccc23edf449c47076b1c85ea2685fa4..8e4e6c2fc8aa1e51d372a95a68da2bf296267d20 100644 (file)
@@ -2953,7 +2953,6 @@ minmax_multi_get_strategy_procinfo(BrinDesc *bdesc, uint16 attno, Oid subtype,
                HeapTuple       tuple;
                Oid                     opfamily,
                                        oprid;
-               bool            isNull;
 
                opfamily = bdesc->bd_index->rd_opfamily[attno - 1];
                attr = TupleDescAttr(bdesc->bd_tupdesc, attno - 1);
@@ -2965,10 +2964,10 @@ minmax_multi_get_strategy_procinfo(BrinDesc *bdesc, uint16 attno, Oid subtype,
                        elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
                                 strategynum, attr->atttypid, subtype, opfamily);
 
-               oprid = DatumGetObjectId(SysCacheGetAttr(AMOPSTRATEGY, tuple,
-                                                                                                Anum_pg_amop_amopopr, &isNull));
+               oprid = DatumGetObjectId(SysCacheGetAttrNotNull(AMOPSTRATEGY, tuple,
+                                                                                                               Anum_pg_amop_amopopr));
                ReleaseSysCache(tuple);
-               Assert(!isNull && RegProcedureIsValid(oprid));
+               Assert(RegProcedureIsValid(oprid));
 
                fmgr_info_cxt(get_opcode(oprid),
                                          &opaque->strategy_procinfos[strategynum - 1],
index dbf147ed22e65c566c60d477e6cf06f76d73ea78..b25b03f7abc3299f511a839c847083ebf349eb21 100644 (file)
@@ -961,7 +961,6 @@ index_opclass_options(Relation indrel, AttrNumber attnum, Datum attoptions,
                Oid                     opclass;
                Datum           indclassDatum;
                oidvector  *indclass;
-               bool            isnull;
 
                if (!DatumGetPointer(attoptions))
                        return NULL;            /* ok, no options, no procedure */
@@ -970,9 +969,8 @@ index_opclass_options(Relation indrel, AttrNumber attnum, Datum attoptions,
                 * Report an error if the opclass's options-parsing procedure does not
                 * exist but the opclass options are specified.
                 */
-               indclassDatum = SysCacheGetAttr(INDEXRELID, indrel->rd_indextuple,
-                                                                               Anum_pg_index_indclass, &isnull);
-               Assert(!isnull);
+               indclassDatum = SysCacheGetAttrNotNull(INDEXRELID, indrel->rd_indextuple,
+                                                                                          Anum_pg_index_indclass);
                indclass = (oidvector *) DatumGetPointer(indclassDatum);
                opclass = indclass->values[attnum - 1];
 
index c4232344aab93a711bee071eced5f3a359ec90e0..45cdcd3dc6c89fcde13ecdc46ccc29059743287a 100644 (file)
@@ -2178,11 +2178,9 @@ ExecGrant_common(InternalGrant *istmt, Oid classid, AclMode default_privs,
                 * Get owner ID and working copy of existing ACL. If there's no ACL,
                 * substitute the proper default.
                 */
-               ownerId = DatumGetObjectId(SysCacheGetAttr(cacheid,
-                                                                                                  tuple,
-                                                                                                  get_object_attnum_owner(classid),
-                                                                                                  &isNull));
-               Assert(!isNull);
+               ownerId = DatumGetObjectId(SysCacheGetAttrNotNull(cacheid,
+                                                                                                                 tuple,
+                                                                                                                 get_object_attnum_owner(classid)));
                aclDatum = SysCacheGetAttr(cacheid,
                                                                   tuple,
                                                                   get_object_attnum_acl(classid),
@@ -2206,10 +2204,8 @@ ExecGrant_common(InternalGrant *istmt, Oid classid, AclMode default_privs,
                                                        old_acl, ownerId,
                                                        &grantorId, &avail_goptions);
 
-               nameDatum = SysCacheGetAttr(cacheid, tuple,
-                                                                       get_object_attnum_name(classid),
-                                                                       &isNull);
-               Assert(!isNull);
+               nameDatum = SysCacheGetAttrNotNull(cacheid, tuple,
+                                                                                  get_object_attnum_name(classid));
 
                /*
                 * Restrict the privileges to what we can actually grant, and emit the
@@ -2476,10 +2472,8 @@ ExecGrant_Parameter(InternalGrant *istmt)
                                 parameterId);
 
                /* We'll need the GUC's name */
-               nameDatum = SysCacheGetAttr(PARAMETERACLOID, tuple,
-                                                                       Anum_pg_parameter_acl_parname,
-                                                                       &isNull);
-               Assert(!isNull);
+               nameDatum = SysCacheGetAttrNotNull(PARAMETERACLOID, tuple,
+                                                                                  Anum_pg_parameter_acl_parname);
                parname = TextDatumGetCString(nameDatum);
 
                /* Treat all parameters as belonging to the bootstrap superuser. */
@@ -3113,11 +3107,9 @@ object_aclmask(Oid classid, Oid objectid, Oid roleid,
                                (errcode(ERRCODE_UNDEFINED_DATABASE),
                                 errmsg("%s with OID %u does not exist", get_object_class_descr(classid), objectid)));
 
-       ownerId = DatumGetObjectId(SysCacheGetAttr(cacheid,
-                                                                                          tuple,
-                                                                                          get_object_attnum_owner(classid),
-                                                                                          &isNull));
-       Assert(!isNull);
+       ownerId = DatumGetObjectId(SysCacheGetAttrNotNull(cacheid,
+                                                                                                         tuple,
+                                                                                                         get_object_attnum_owner(classid)));
 
        aclDatum = SysCacheGetAttr(cacheid, tuple, get_object_attnum_acl(classid),
                                                           &isNull);
@@ -3994,7 +3986,6 @@ object_ownercheck(Oid classid, Oid objectid, Oid roleid)
        if (cacheid != -1)
        {
                HeapTuple       tuple;
-               bool            isnull;
 
                tuple = SearchSysCache1(cacheid, ObjectIdGetDatum(objectid));
                if (!HeapTupleIsValid(tuple))
@@ -4002,12 +3993,9 @@ object_ownercheck(Oid classid, Oid objectid, Oid roleid)
                                        (errcode(ERRCODE_UNDEFINED_OBJECT),
                                         errmsg("%s with OID %u does not exist", get_object_class_descr(classid), objectid)));
 
-               ownerId = DatumGetObjectId(SysCacheGetAttr(cacheid,
-                                                                                                  tuple,
-                                                                                                  get_object_attnum_owner(classid),
-                                                                                                  &isnull));
-               Assert(!isnull);
-
+               ownerId = DatumGetObjectId(SysCacheGetAttrNotNull(cacheid,
+                                                                                                                 tuple,
+                                                                                                                 get_object_attnum_owner(classid)));
                ReleaseSysCache(tuple);
        }
        else
index 33e3d0ec055b9c68c30f60e77df38434871577bf..c64fde4b7949babe74c057ac50ecd5cd3da3cb61 100644 (file)
@@ -1320,14 +1320,12 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId,
        indexTuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(oldIndexId));
        if (!HeapTupleIsValid(indexTuple))
                elog(ERROR, "cache lookup failed for index %u", oldIndexId);
-       indclassDatum = SysCacheGetAttr(INDEXRELID, indexTuple,
-                                                                       Anum_pg_index_indclass, &isnull);
-       Assert(!isnull);
+       indclassDatum = SysCacheGetAttrNotNull(INDEXRELID, indexTuple,
+                                                                                  Anum_pg_index_indclass);
        indclass = (oidvector *) DatumGetPointer(indclassDatum);
 
-       colOptionDatum = SysCacheGetAttr(INDEXRELID, indexTuple,
-                                                                        Anum_pg_index_indoption, &isnull);
-       Assert(!isnull);
+       colOptionDatum = SysCacheGetAttrNotNull(INDEXRELID, indexTuple,
+                                                                                       Anum_pg_index_indoption);
        indcoloptions = (int2vector *) DatumGetPointer(colOptionDatum);
 
        /* Fetch options of index if any */
@@ -1347,9 +1345,8 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId,
                Datum           exprDatum;
                char       *exprString;
 
-               exprDatum = SysCacheGetAttr(INDEXRELID, indexTuple,
-                                                                       Anum_pg_index_indexprs, &isnull);
-               Assert(!isnull);
+               exprDatum = SysCacheGetAttrNotNull(INDEXRELID, indexTuple,
+                                                                                  Anum_pg_index_indexprs);
                exprString = TextDatumGetCString(exprDatum);
                indexExprs = (List *) stringToNode(exprString);
                pfree(exprString);
@@ -1359,9 +1356,8 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId,
                Datum           predDatum;
                char       *predString;
 
-               predDatum = SysCacheGetAttr(INDEXRELID, indexTuple,
-                                                                       Anum_pg_index_indpred, &isnull);
-               Assert(!isnull);
+               predDatum = SysCacheGetAttrNotNull(INDEXRELID, indexTuple,
+                                                                                  Anum_pg_index_indpred);
                predString = TextDatumGetCString(predDatum);
                indexPreds = (List *) stringToNode(predString);
 
index d59492934cb60d0c91fdfc514267d9fbefb4a14d..95fefc7565bfbe1e6f6e53fa07bd6dd465a8d30a 100644 (file)
@@ -2603,7 +2603,6 @@ get_object_namespace(const ObjectAddress *address)
 {
        int                     cache;
        HeapTuple       tuple;
-       bool            isnull;
        Oid                     oid;
        const ObjectPropertyType *property;
 
@@ -2621,11 +2620,9 @@ get_object_namespace(const ObjectAddress *address)
        if (!HeapTupleIsValid(tuple))
                elog(ERROR, "cache lookup failed for cache %d oid %u",
                         cache, address->objectId);
-       oid = DatumGetObjectId(SysCacheGetAttr(cache,
-                                                                                  tuple,
-                                                                                  property->attnum_namespace,
-                                                                                  &isnull));
-       Assert(!isnull);
+       oid = DatumGetObjectId(SysCacheGetAttrNotNull(cache,
+                                                                                                 tuple,
+                                                                                                 property->attnum_namespace));
        ReleaseSysCache(tuple);
 
        return oid;
@@ -3896,7 +3893,6 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok)
                        {
                                HeapTuple       tup;
                                Datum           nameDatum;
-                               bool            isNull;
                                char       *parname;
 
                                tup = SearchSysCache1(PARAMETERACLOID,
@@ -3908,10 +3904,8 @@ getObjectDescription(const ObjectAddress *object, bool missing_ok)
                                                         object->objectId);
                                        break;
                                }
-                               nameDatum = SysCacheGetAttr(PARAMETERACLOID, tup,
-                                                                                       Anum_pg_parameter_acl_parname,
-                                                                                       &isNull);
-                               Assert(!isNull);
+                               nameDatum = SysCacheGetAttrNotNull(PARAMETERACLOID, tup,
+                                                                                                  Anum_pg_parameter_acl_parname);
                                parname = TextDatumGetCString(nameDatum);
                                appendStringInfo(&buffer, _("parameter %s"), parname);
                                ReleaseSysCache(tup);
@@ -5759,7 +5753,6 @@ getObjectIdentityParts(const ObjectAddress *object,
                        {
                                HeapTuple       tup;
                                Datum           nameDatum;
-                               bool            isNull;
                                char       *parname;
 
                                tup = SearchSysCache1(PARAMETERACLOID,
@@ -5771,10 +5764,8 @@ getObjectIdentityParts(const ObjectAddress *object,
                                                         object->objectId);
                                        break;
                                }
-                               nameDatum = SysCacheGetAttr(PARAMETERACLOID, tup,
-                                                                                       Anum_pg_parameter_acl_parname,
-                                                                                       &isNull);
-                               Assert(!isNull);
+                               nameDatum = SysCacheGetAttrNotNull(PARAMETERACLOID, tup,
+                                                                                                  Anum_pg_parameter_acl_parname);
                                parname = TextDatumGetCString(nameDatum);
                                appendStringInfoString(&buffer, parname);
                                if (objname)
index 7392c72e9003e3ced15bae6e964631513d97986c..ce82ede7f9010fe5b18f2478067e41a5c41ca516 100644 (file)
@@ -1190,23 +1190,18 @@ DeconstructFkConstraintRow(HeapTuple tuple, int *numfks,
                                                   Oid *pf_eq_oprs, Oid *pp_eq_oprs, Oid *ff_eq_oprs,
                                                   int *num_fk_del_set_cols, AttrNumber *fk_del_set_cols)
 {
-       Oid                     constrId;
        Datum           adatum;
        bool            isNull;
        ArrayType  *arr;
        int                     numkeys;
 
-       constrId = ((Form_pg_constraint) GETSTRUCT(tuple))->oid;
-
        /*
         * We expect the arrays to be 1-D arrays of the right types; verify that.
         * We don't need to use deconstruct_array() since the array data is just
         * going to look like a C array of values.
         */
-       adatum = SysCacheGetAttr(CONSTROID, tuple,
-                                                        Anum_pg_constraint_conkey, &isNull);
-       if (isNull)
-               elog(ERROR, "null conkey for constraint %u", constrId);
+       adatum = SysCacheGetAttrNotNull(CONSTROID, tuple,
+                                                                       Anum_pg_constraint_conkey);
        arr = DatumGetArrayTypeP(adatum);       /* ensure not toasted */
        if (ARR_NDIM(arr) != 1 ||
                ARR_HASNULL(arr) ||
@@ -1219,10 +1214,8 @@ DeconstructFkConstraintRow(HeapTuple tuple, int *numfks,
        if ((Pointer) arr != DatumGetPointer(adatum))
                pfree(arr);                             /* free de-toasted copy, if any */
 
-       adatum = SysCacheGetAttr(CONSTROID, tuple,
-                                                        Anum_pg_constraint_confkey, &isNull);
-       if (isNull)
-               elog(ERROR, "null confkey for constraint %u", constrId);
+       adatum = SysCacheGetAttrNotNull(CONSTROID, tuple,
+                                                                       Anum_pg_constraint_confkey);
        arr = DatumGetArrayTypeP(adatum);       /* ensure not toasted */
        if (ARR_NDIM(arr) != 1 ||
                ARR_DIMS(arr)[0] != numkeys ||
@@ -1235,10 +1228,8 @@ DeconstructFkConstraintRow(HeapTuple tuple, int *numfks,
 
        if (pf_eq_oprs)
        {
-               adatum = SysCacheGetAttr(CONSTROID, tuple,
-                                                                Anum_pg_constraint_conpfeqop, &isNull);
-               if (isNull)
-                       elog(ERROR, "null conpfeqop for constraint %u", constrId);
+               adatum = SysCacheGetAttrNotNull(CONSTROID, tuple,
+                                                                               Anum_pg_constraint_conpfeqop);
                arr = DatumGetArrayTypeP(adatum);       /* ensure not toasted */
                /* see TryReuseForeignKey if you change the test below */
                if (ARR_NDIM(arr) != 1 ||
@@ -1253,10 +1244,8 @@ DeconstructFkConstraintRow(HeapTuple tuple, int *numfks,
 
        if (pp_eq_oprs)
        {
-               adatum = SysCacheGetAttr(CONSTROID, tuple,
-                                                                Anum_pg_constraint_conppeqop, &isNull);
-               if (isNull)
-                       elog(ERROR, "null conppeqop for constraint %u", constrId);
+               adatum = SysCacheGetAttrNotNull(CONSTROID, tuple,
+                                                                               Anum_pg_constraint_conppeqop);
                arr = DatumGetArrayTypeP(adatum);       /* ensure not toasted */
                if (ARR_NDIM(arr) != 1 ||
                        ARR_DIMS(arr)[0] != numkeys ||
@@ -1270,10 +1259,8 @@ DeconstructFkConstraintRow(HeapTuple tuple, int *numfks,
 
        if (ff_eq_oprs)
        {
-               adatum = SysCacheGetAttr(CONSTROID, tuple,
-                                                                Anum_pg_constraint_conffeqop, &isNull);
-               if (isNull)
-                       elog(ERROR, "null conffeqop for constraint %u", constrId);
+               adatum = SysCacheGetAttrNotNull(CONSTROID, tuple,
+                                                                               Anum_pg_constraint_conffeqop);
                arr = DatumGetArrayTypeP(adatum);       /* ensure not toasted */
                if (ARR_NDIM(arr) != 1 ||
                        ARR_DIMS(arr)[0] != numkeys ||
index 14d552fe2dd29e9ef00397a9a8465c338dee55d8..41fa2a49878d1b3a7ed4db102394498a1cbd4ed7 100644 (file)
@@ -520,10 +520,8 @@ ProcedureCreate(const char *procedureName,
                                                                 dropcmd,
                                                                 format_procedure(oldproc->oid))));
 
-                       proargdefaults = SysCacheGetAttr(PROCNAMEARGSNSP, oldtup,
-                                                                                        Anum_pg_proc_proargdefaults,
-                                                                                        &isnull);
-                       Assert(!isnull);
+                       proargdefaults = SysCacheGetAttrNotNull(PROCNAMEARGSNSP, oldtup,
+                                                                                                       Anum_pg_proc_proargdefaults);
                        oldDefaults = castNode(List, stringToNode(TextDatumGetCString(proargdefaults)));
                        Assert(list_length(oldDefaults) == oldproc->pronargdefaults);
 
@@ -731,7 +729,6 @@ fmgr_internal_validator(PG_FUNCTION_ARGS)
 {
        Oid                     funcoid = PG_GETARG_OID(0);
        HeapTuple       tuple;
-       bool            isnull;
        Datum           tmp;
        char       *prosrc;
 
@@ -747,9 +744,7 @@ fmgr_internal_validator(PG_FUNCTION_ARGS)
        if (!HeapTupleIsValid(tuple))
                elog(ERROR, "cache lookup failed for function %u", funcoid);
 
-       tmp = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_prosrc, &isnull);
-       if (isnull)
-               elog(ERROR, "null prosrc");
+       tmp = SysCacheGetAttrNotNull(PROCOID, tuple, Anum_pg_proc_prosrc);
        prosrc = TextDatumGetCString(tmp);
 
        if (fmgr_internal_function(prosrc) == InvalidOid)
@@ -778,7 +773,6 @@ fmgr_c_validator(PG_FUNCTION_ARGS)
        Oid                     funcoid = PG_GETARG_OID(0);
        void       *libraryhandle;
        HeapTuple       tuple;
-       bool            isnull;
        Datum           tmp;
        char       *prosrc;
        char       *probin;
@@ -796,14 +790,10 @@ fmgr_c_validator(PG_FUNCTION_ARGS)
        if (!HeapTupleIsValid(tuple))
                elog(ERROR, "cache lookup failed for function %u", funcoid);
 
-       tmp = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_prosrc, &isnull);
-       if (isnull)
-               elog(ERROR, "null prosrc for C function %u", funcoid);
+       tmp = SysCacheGetAttrNotNull(PROCOID, tuple, Anum_pg_proc_prosrc);
        prosrc = TextDatumGetCString(tmp);
 
-       tmp = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_probin, &isnull);
-       if (isnull)
-               elog(ERROR, "null probin for C function %u", funcoid);
+       tmp = SysCacheGetAttrNotNull(PROCOID, tuple, Anum_pg_proc_probin);
        probin = TextDatumGetCString(tmp);
 
        (void) load_external_function(probin, prosrc, true, &libraryhandle);
@@ -876,10 +866,7 @@ fmgr_sql_validator(PG_FUNCTION_ARGS)
        /* Postpone body checks if !check_function_bodies */
        if (check_function_bodies)
        {
-               tmp = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_prosrc, &isnull);
-               if (isnull)
-                       elog(ERROR, "null prosrc");
-
+               tmp = SysCacheGetAttrNotNull(PROCOID, tuple, Anum_pg_proc_prosrc);
                prosrc = TextDatumGetCString(tmp);
 
                /*
index a56ae311c3dfc66b8ab82c786b4a9c30a77d23e5..d322b9482c5a95a021579bd55ed24b3ed32cbef2 100644 (file)
@@ -73,11 +73,9 @@ GetSubscription(Oid subid, bool missing_ok)
        sub->disableonerr = subform->subdisableonerr;
 
        /* Get conninfo */
-       datum = SysCacheGetAttr(SUBSCRIPTIONOID,
-                                                       tup,
-                                                       Anum_pg_subscription_subconninfo,
-                                                       &isnull);
-       Assert(!isnull);
+       datum = SysCacheGetAttrNotNull(SUBSCRIPTIONOID,
+                                                                  tup,
+                                                                  Anum_pg_subscription_subconninfo);
        sub->conninfo = TextDatumGetCString(datum);
 
        /* Get slotname */
@@ -91,27 +89,21 @@ GetSubscription(Oid subid, bool missing_ok)
                sub->slotname = NULL;
 
        /* Get synccommit */
-       datum = SysCacheGetAttr(SUBSCRIPTIONOID,
-                                                       tup,
-                                                       Anum_pg_subscription_subsynccommit,
-                                                       &isnull);
-       Assert(!isnull);
+       datum = SysCacheGetAttrNotNull(SUBSCRIPTIONOID,
+                                                                  tup,
+                                                                  Anum_pg_subscription_subsynccommit);
        sub->synccommit = TextDatumGetCString(datum);
 
        /* Get publications */
-       datum = SysCacheGetAttr(SUBSCRIPTIONOID,
-                                                       tup,
-                                                       Anum_pg_subscription_subpublications,
-                                                       &isnull);
-       Assert(!isnull);
+       datum = SysCacheGetAttrNotNull(SUBSCRIPTIONOID,
+                                                                  tup,
+                                                                  Anum_pg_subscription_subpublications);
        sub->publications = textarray_to_stringlist(DatumGetArrayTypeP(datum));
 
        /* Get origin */
-       datum = SysCacheGetAttr(SUBSCRIPTIONOID,
-                                                       tup,
-                                                       Anum_pg_subscription_suborigin,
-                                                       &isnull);
-       Assert(!isnull);
+       datum = SysCacheGetAttrNotNull(SUBSCRIPTIONOID,
+                                                                  tup,
+                                                                  Anum_pg_subscription_suborigin);
        sub->origin = TextDatumGetCString(datum);
 
        ReleaseSysCache(tup);
index 3d0aea0568586cce46aaa63abf4e5ad074253c5e..13ad7dff426f0ee0bb5cfc205500f0df17f846d6 100644 (file)
@@ -404,9 +404,7 @@ AlterCollation(AlterCollationStmt *stmt)
        datum = SysCacheGetAttr(COLLOID, tup, Anum_pg_collation_collversion, &isnull);
        oldversion = isnull ? NULL : TextDatumGetCString(datum);
 
-       datum = SysCacheGetAttr(COLLOID, tup, collForm->collprovider == COLLPROVIDER_ICU ? Anum_pg_collation_colliculocale : Anum_pg_collation_collcollate, &isnull);
-       if (isnull)
-               elog(ERROR, "unexpected null in pg_collation");
+       datum = SysCacheGetAttrNotNull(COLLOID, tup, collForm->collprovider == COLLPROVIDER_ICU ? Anum_pg_collation_colliculocale : Anum_pg_collation_collcollate);
        newversion = get_collation_actual_version(collForm->collprovider, TextDatumGetCString(datum));
 
        /* cannot change from NULL to non-NULL or vice versa */
@@ -457,7 +455,6 @@ pg_collation_actual_version(PG_FUNCTION_ARGS)
        char    *locale;
        char    *version;
        Datum    datum;
-       bool     isnull;
 
        if (collid == DEFAULT_COLLATION_OID)
        {
@@ -471,12 +468,9 @@ pg_collation_actual_version(PG_FUNCTION_ARGS)
 
                provider = ((Form_pg_database) GETSTRUCT(dbtup))->datlocprovider;
 
-               datum = SysCacheGetAttr(DATABASEOID, dbtup,
-                                                               provider == COLLPROVIDER_ICU ?
-                                                               Anum_pg_database_daticulocale : Anum_pg_database_datcollate,
-                                                               &isnull);
-               if (isnull)
-                       elog(ERROR, "unexpected null in pg_database");
+               datum = SysCacheGetAttrNotNull(DATABASEOID, dbtup,
+                                                                          provider == COLLPROVIDER_ICU ?
+                                                                          Anum_pg_database_daticulocale : Anum_pg_database_datcollate);
 
                locale = TextDatumGetCString(datum);
 
@@ -494,12 +488,9 @@ pg_collation_actual_version(PG_FUNCTION_ARGS)
 
                provider = ((Form_pg_collation) GETSTRUCT(colltp))->collprovider;
                Assert(provider != COLLPROVIDER_DEFAULT);
-               datum = SysCacheGetAttr(COLLOID, colltp,
-                                                               provider == COLLPROVIDER_ICU ?
-                                                               Anum_pg_collation_colliculocale : Anum_pg_collation_collcollate,
-                                                               &isnull);
-               if (isnull)
-                       elog(ERROR, "unexpected null in pg_collation");
+               datum = SysCacheGetAttrNotNull(COLLOID, colltp,
+                                                                          provider == COLLPROVIDER_ICU ?
+                                                                          Anum_pg_collation_colliculocale : Anum_pg_collation_collcollate);
 
                locale = TextDatumGetCString(datum);
 
index 4d5d5d686667d1f1ffdfd308996d889eaddaefc9..9408dd6cc7ea352aa8bb0a728c9b34c8904cab7c 100644 (file)
@@ -2597,7 +2597,6 @@ pg_database_collation_actual_version(PG_FUNCTION_ARGS)
        HeapTuple       tp;
        char            datlocprovider;
        Datum           datum;
-       bool            isnull;
        char       *version;
 
        tp = SearchSysCache1(DATABASEOID, ObjectIdGetDatum(dbid));
@@ -2608,9 +2607,7 @@ pg_database_collation_actual_version(PG_FUNCTION_ARGS)
 
        datlocprovider = ((Form_pg_database) GETSTRUCT(tp))->datlocprovider;
 
-       datum = SysCacheGetAttr(DATABASEOID, tp, datlocprovider == COLLPROVIDER_ICU ? Anum_pg_database_daticulocale : Anum_pg_database_datcollate, &isnull);
-       if (isnull)
-               elog(ERROR, "unexpected null in pg_database");
+       datum = SysCacheGetAttrNotNull(DATABASEOID, tp, datlocprovider == COLLPROVIDER_ICU ? Anum_pg_database_daticulocale : Anum_pg_database_datcollate);
        version = get_collation_actual_version(datlocprovider, TextDatumGetCString(datum));
 
        ReleaseSysCache(tp);
@@ -2737,14 +2734,12 @@ get_db_info(const char *name, LOCKMODE lockmode,
                                        *dbLocProvider = dbform->datlocprovider;
                                if (dbCollate)
                                {
-                                       datum = SysCacheGetAttr(DATABASEOID, tuple, Anum_pg_database_datcollate, &isnull);
-                                       Assert(!isnull);
+                                       datum = SysCacheGetAttrNotNull(DATABASEOID, tuple, Anum_pg_database_datcollate);
                                        *dbCollate = TextDatumGetCString(datum);
                                }
                                if (dbCtype)
                                {
-                                       datum = SysCacheGetAttr(DATABASEOID, tuple, Anum_pg_database_datctype, &isnull);
-                                       Assert(!isnull);
+                                       datum = SysCacheGetAttrNotNull(DATABASEOID, tuple, Anum_pg_database_datctype);
                                        *dbCtype = TextDatumGetCString(datum);
                                }
                                if (dbIculocale)
index 3ec8b5cca6c2dabd5f67a2c5c710fe45a409b7be..e6ee99e51f6d203992024d36fd73e2994589f3bd 100644 (file)
@@ -189,7 +189,6 @@ CheckIndexCompatible(Oid oldId,
        IndexInfo  *indexInfo;
        int                     numberOfAttributes;
        int                     old_natts;
-       bool            isnull;
        bool            ret = true;
        oidvector  *old_indclass;
        oidvector  *old_indcollation;
@@ -270,12 +269,10 @@ CheckIndexCompatible(Oid oldId,
        old_natts = indexForm->indnkeyatts;
        Assert(old_natts == numberOfAttributes);
 
-       d = SysCacheGetAttr(INDEXRELID, tuple, Anum_pg_index_indcollation, &isnull);
-       Assert(!isnull);
+       d = SysCacheGetAttrNotNull(INDEXRELID, tuple, Anum_pg_index_indcollation);
        old_indcollation = (oidvector *) DatumGetPointer(d);
 
-       d = SysCacheGetAttr(INDEXRELID, tuple, Anum_pg_index_indclass, &isnull);
-       Assert(!isnull);
+       d = SysCacheGetAttrNotNull(INDEXRELID, tuple, Anum_pg_index_indclass);
        old_indclass = (oidvector *) DatumGetPointer(d);
 
        ret = (memcmp(old_indclass->values, classObjectId,
index fb30d2595cfa072d3bef0cb4645cb8221d23f7cd..c00b9df3e3bcb1c13ee4f11593d2ad1118c271de 100644 (file)
@@ -692,15 +692,12 @@ refresh_by_match_merge(Oid matviewOid, Oid tempOid, Oid relowner,
                        int                     indnkeyatts = indexStruct->indnkeyatts;
                        oidvector  *indclass;
                        Datum           indclassDatum;
-                       bool            isnull;
                        int                     i;
 
                        /* Must get indclass the hard way. */
-                       indclassDatum = SysCacheGetAttr(INDEXRELID,
-                                                                                       indexRel->rd_indextuple,
-                                                                                       Anum_pg_index_indclass,
-                                                                                       &isnull);
-                       Assert(!isnull);
+                       indclassDatum = SysCacheGetAttrNotNull(INDEXRELID,
+                                                                                                  indexRel->rd_indextuple,
+                                                                                                  Anum_pg_index_indclass);
                        indclass = (oidvector *) DatumGetPointer(indclassDatum);
 
                        /* Add quals for all columns from this index. */
index 464db6d247fdc9173f36697e65215eb4b3901512..8a26ddab1c704c10bd4ce3f391f0202991bfa39e 100644 (file)
@@ -1436,15 +1436,13 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
        LockSharedObject(SubscriptionRelationId, subid, 0, AccessExclusiveLock);
 
        /* Get subname */
-       datum = SysCacheGetAttr(SUBSCRIPTIONOID, tup,
-                                                       Anum_pg_subscription_subname, &isnull);
-       Assert(!isnull);
+       datum = SysCacheGetAttrNotNull(SUBSCRIPTIONOID, tup,
+                                                                  Anum_pg_subscription_subname);
        subname = pstrdup(NameStr(*DatumGetName(datum)));
 
        /* Get conninfo */
-       datum = SysCacheGetAttr(SUBSCRIPTIONOID, tup,
-                                                       Anum_pg_subscription_subconninfo, &isnull);
-       Assert(!isnull);
+       datum = SysCacheGetAttrNotNull(SUBSCRIPTIONOID, tup,
+                                                                  Anum_pg_subscription_subconninfo);
        conninfo = TextDatumGetCString(datum);
 
        /* Get slotname */
index 9a877f90d363c31a4f665983928c1fd8a6bce11b..9b0a0142d3b531f06d33608132398ba5733690bd 100644 (file)
@@ -11116,7 +11116,6 @@ ATExecValidateConstraint(List **wqueue, Relation rel, char *constrName,
                        List       *children = NIL;
                        ListCell   *child;
                        NewConstraint *newcon;
-                       bool            isnull;
                        Datum           val;
                        char       *conbin;
 
@@ -11171,11 +11170,8 @@ ATExecValidateConstraint(List **wqueue, Relation rel, char *constrName,
                        newcon->refindid = InvalidOid;
                        newcon->conid = con->oid;
 
-                       val = SysCacheGetAttr(CONSTROID, tuple,
-                                                                 Anum_pg_constraint_conbin, &isnull);
-                       if (isnull)
-                               elog(ERROR, "null conbin for constraint %u", con->oid);
-
+                       val = SysCacheGetAttrNotNull(CONSTROID, tuple,
+                                                                                Anum_pg_constraint_conbin);
                        conbin = TextDatumGetCString(val);
                        newcon->qual = (Node *) stringToNode(conbin);
 
@@ -11277,7 +11273,6 @@ transformFkeyGetPrimaryKey(Relation pkrel, Oid *indexOid,
        HeapTuple       indexTuple = NULL;
        Form_pg_index indexStruct = NULL;
        Datum           indclassDatum;
-       bool            isnull;
        oidvector  *indclass;
        int                     i;
 
@@ -11329,9 +11324,8 @@ transformFkeyGetPrimaryKey(Relation pkrel, Oid *indexOid,
                                                RelationGetRelationName(pkrel))));
 
        /* Must get indclass the hard way */
-       indclassDatum = SysCacheGetAttr(INDEXRELID, indexTuple,
-                                                                       Anum_pg_index_indclass, &isnull);
-       Assert(!isnull);
+       indclassDatum = SysCacheGetAttrNotNull(INDEXRELID, indexTuple,
+                                                                                  Anum_pg_index_indclass);
        indclass = (oidvector *) DatumGetPointer(indclassDatum);
 
        /*
@@ -11424,13 +11418,11 @@ transformFkeyCheckAttrs(Relation pkrel,
                        heap_attisnull(indexTuple, Anum_pg_index_indexprs, NULL))
                {
                        Datum           indclassDatum;
-                       bool            isnull;
                        oidvector  *indclass;
 
                        /* Must get indclass the hard way */
-                       indclassDatum = SysCacheGetAttr(INDEXRELID, indexTuple,
-                                                                                       Anum_pg_index_indclass, &isnull);
-                       Assert(!isnull);
+                       indclassDatum = SysCacheGetAttrNotNull(INDEXRELID, indexTuple,
+                                                                                                  Anum_pg_index_indclass);
                        indclass = (oidvector *) DatumGetPointer(indclassDatum);
 
                        /*
@@ -13582,7 +13574,6 @@ TryReuseForeignKey(Oid oldId, Constraint *con)
 {
        HeapTuple       tup;
        Datum           adatum;
-       bool            isNull;
        ArrayType  *arr;
        Oid                *rawarr;
        int                     numkeys;
@@ -13595,10 +13586,8 @@ TryReuseForeignKey(Oid oldId, Constraint *con)
        if (!HeapTupleIsValid(tup)) /* should not happen */
                elog(ERROR, "cache lookup failed for constraint %u", oldId);
 
-       adatum = SysCacheGetAttr(CONSTROID, tup,
-                                                        Anum_pg_constraint_conpfeqop, &isNull);
-       if (isNull)
-               elog(ERROR, "null conpfeqop for constraint %u", oldId);
+       adatum = SysCacheGetAttrNotNull(CONSTROID, tup,
+                                                                       Anum_pg_constraint_conpfeqop);
        arr = DatumGetArrayTypeP(adatum);       /* ensure not toasted */
        numkeys = ARR_DIMS(arr)[0];
        /* test follows the one in ri_FetchConstraintInfo() */
index 04bddaef81e29dfe4c6c25ef5bf02856201bd547..3440dbc4405b8cf2da3ac7e295ae922abea2d3d2 100644 (file)
@@ -3039,7 +3039,6 @@ AlterDomainValidateConstraint(List *names, const char *constrName)
        char       *conbin;
        SysScanDesc scan;
        Datum           val;
-       bool            isnull;
        HeapTuple       tuple;
        HeapTuple       copyTuple;
        ScanKeyData skey[3];
@@ -3094,12 +3093,7 @@ AlterDomainValidateConstraint(List *names, const char *constrName)
                                 errmsg("constraint \"%s\" of domain \"%s\" is not a check constraint",
                                                constrName, TypeNameToString(typename))));
 
-       val = SysCacheGetAttr(CONSTROID, tuple,
-                                                 Anum_pg_constraint_conbin,
-                                                 &isnull);
-       if (isnull)
-               elog(ERROR, "null conbin for constraint %u",
-                        con->oid);
+       val = SysCacheGetAttrNotNull(CONSTROID, tuple, Anum_pg_constraint_conbin);
        conbin = TextDatumGetCString(val);
 
        validateDomainConstraint(domainoid, conbin);
index 349bed0f5d348c5ad9f0ec569593f841c787c956..9dd716846157b63da9a0582258162c93c9a1cd5c 100644 (file)
@@ -60,14 +60,12 @@ build_replindex_scan_key(ScanKey skey, Relation rel, Relation idxrel,
 {
        int                     index_attoff;
        int                     skey_attoff = 0;
-       bool            isnull;
        Datum           indclassDatum;
        oidvector  *opclass;
        int2vector *indkey = &idxrel->rd_index->indkey;
 
-       indclassDatum = SysCacheGetAttr(INDEXRELID, idxrel->rd_indextuple,
-                                                                       Anum_pg_index_indclass, &isnull);
-       Assert(!isnull);
+       indclassDatum = SysCacheGetAttrNotNull(INDEXRELID, idxrel->rd_indextuple,
+                                                                                  Anum_pg_index_indclass);
        opclass = (oidvector *) DatumGetPointer(indclassDatum);
 
        /* Build scankey for every non-expression attribute in the index. */
index 50e06ec6931cd47919d997f281b07c9945c71938..f55424eb5ad8a97ba3c76169860762c05015d8cd 100644 (file)
@@ -660,12 +660,7 @@ init_sql_fcache(FunctionCallInfo fcinfo, Oid collation, bool lazyEvalOK)
        /*
         * And of course we need the function body text.
         */
-       tmp = SysCacheGetAttr(PROCOID,
-                                                 procedureTuple,
-                                                 Anum_pg_proc_prosrc,
-                                                 &isNull);
-       if (isNull)
-               elog(ERROR, "null prosrc for function %u", foid);
+       tmp = SysCacheGetAttrNotNull(PROCOID, procedureTuple, Anum_pg_proc_prosrc);
        fcache->src = TextDatumGetCString(tmp);
 
        /* If we have prosqlbody, pay attention to that not prosrc. */
index 76e25118f9425934df8c26ad87dba7067978a5d8..fc245c60e413645e360436cb6e510d3929cfca1e 100644 (file)
@@ -4177,15 +4177,10 @@ fetch_function_defaults(HeapTuple func_tuple)
 {
        List       *defaults;
        Datum           proargdefaults;
-       bool            isnull;
        char       *str;
 
-       /* The error cases here shouldn't happen, but check anyway */
-       proargdefaults = SysCacheGetAttr(PROCOID, func_tuple,
-                                                                        Anum_pg_proc_proargdefaults,
-                                                                        &isnull);
-       if (isnull)
-               elog(ERROR, "not enough default arguments");
+       proargdefaults = SysCacheGetAttrNotNull(PROCOID, func_tuple,
+                                                                                       Anum_pg_proc_proargdefaults);
        str = TextDatumGetCString(proargdefaults);
        defaults = castNode(List, stringToNode(str));
        pfree(str);
@@ -4457,12 +4452,7 @@ inline_function(Oid funcid, Oid result_type, Oid result_collid,
        fexpr->location = -1;
 
        /* Fetch the function body */
-       tmp = SysCacheGetAttr(PROCOID,
-                                                 func_tuple,
-                                                 Anum_pg_proc_prosrc,
-                                                 &isNull);
-       if (isNull)
-               elog(ERROR, "null prosrc for function %u", funcid);
+       tmp = SysCacheGetAttrNotNull(PROCOID, func_tuple, Anum_pg_proc_prosrc);
        src = TextDatumGetCString(tmp);
 
        /*
@@ -5015,12 +5005,7 @@ inline_set_returning_function(PlannerInfo *root, RangeTblEntry *rte)
        oldcxt = MemoryContextSwitchTo(mycxt);
 
        /* Fetch the function body */
-       tmp = SysCacheGetAttr(PROCOID,
-                                                 func_tuple,
-                                                 Anum_pg_proc_prosrc,
-                                                 &isNull);
-       if (isNull)
-               elog(ERROR, "null prosrc for function %u", func_oid);
+       tmp = SysCacheGetAttrNotNull(PROCOID, func_tuple, Anum_pg_proc_prosrc);
        src = TextDatumGetCString(tmp);
 
        /*
index ca14f0630863a52cfc02740bbf96ba52fd2ce53b..b3f0b6a137a05ce4a37465983a4684030a3c4143 100644 (file)
@@ -1632,7 +1632,6 @@ func_get_detail(List *funcname,
                if (argdefaults && best_candidate->ndargs > 0)
                {
                        Datum           proargdefaults;
-                       bool            isnull;
                        char       *str;
                        List       *defaults;
 
@@ -1640,10 +1639,8 @@ func_get_detail(List *funcname,
                        if (best_candidate->ndargs > pform->pronargdefaults)
                                elog(ERROR, "not enough default arguments");
 
-                       proargdefaults = SysCacheGetAttr(PROCOID, ftup,
-                                                                                        Anum_pg_proc_proargdefaults,
-                                                                                        &isnull);
-                       Assert(!isnull);
+                       proargdefaults = SysCacheGetAttrNotNull(PROCOID, ftup,
+                                                                                                       Anum_pg_proc_proargdefaults);
                        str = TextDatumGetCString(proargdefaults);
                        defaults = castNode(List, stringToNode(str));
                        pfree(str);
index f9218f48aa7cb730c2447a445435ba9c7dce590c..15a1dab8c5a8d9599231418f4b04caa40a9bb5f4 100644 (file)
@@ -1562,15 +1562,12 @@ generateClonedIndexStmt(RangeVar *heapRel, Relation source_idx,
        amrec = (Form_pg_am) GETSTRUCT(ht_am);
 
        /* Extract indcollation from the pg_index tuple */
-       datum = SysCacheGetAttr(INDEXRELID, ht_idx,
-                                                       Anum_pg_index_indcollation, &isnull);
-       Assert(!isnull);
+       datum = SysCacheGetAttrNotNull(INDEXRELID, ht_idx,
+                                                                  Anum_pg_index_indcollation);
        indcollation = (oidvector *) DatumGetPointer(datum);
 
        /* Extract indclass from the pg_index tuple */
-       datum = SysCacheGetAttr(INDEXRELID, ht_idx,
-                                                       Anum_pg_index_indclass, &isnull);
-       Assert(!isnull);
+       datum = SysCacheGetAttrNotNull(INDEXRELID, ht_idx, Anum_pg_index_indclass);
        indclass = (oidvector *) DatumGetPointer(datum);
 
        /* Begin building the IndexStmt */
@@ -1641,13 +1638,8 @@ generateClonedIndexStmt(RangeVar *heapRel, Relation source_idx,
 
                                Assert(conrec->contype == CONSTRAINT_EXCLUSION);
                                /* Extract operator OIDs from the pg_constraint tuple */
-                               datum = SysCacheGetAttr(CONSTROID, ht_constr,
-                                                                               Anum_pg_constraint_conexclop,
-                                                                               &isnull);
-                               if (isnull)
-                                       elog(ERROR, "null conexclop for constraint %u",
-                                                constraintId);
-
+                               datum = SysCacheGetAttrNotNull(CONSTROID, ht_constr,
+                                                                                          Anum_pg_constraint_conexclop);
                                deconstruct_array_builtin(DatumGetArrayTypeP(datum), OIDOID, &elems, NULL, &nElems);
 
                                for (i = 0; i < nElems; i++)
@@ -1898,9 +1890,8 @@ generateClonedExtStatsStmt(RangeVar *heapRel, Oid heapRelid,
        statsrec = (Form_pg_statistic_ext) GETSTRUCT(ht_stats);
 
        /* Determine which statistics types exist */
-       datum = SysCacheGetAttr(STATEXTOID, ht_stats,
-                                                       Anum_pg_statistic_ext_stxkind, &isnull);
-       Assert(!isnull);
+       datum = SysCacheGetAttrNotNull(STATEXTOID, ht_stats,
+                                                                  Anum_pg_statistic_ext_stxkind);
        arr = DatumGetArrayTypeP(datum);
        if (ARR_NDIM(arr) != 1 ||
                ARR_HASNULL(arr) ||
@@ -2228,7 +2219,6 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
                Form_pg_index index_form;
                oidvector  *indclass;
                Datum           indclassDatum;
-               bool            isnull;
                int                     i;
 
                /* Grammar should not allow this with explicit column list */
@@ -2327,9 +2317,9 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
                                         parser_errposition(cxt->pstate, constraint->location)));
 
                /* Must get indclass the hard way */
-               indclassDatum = SysCacheGetAttr(INDEXRELID, index_rel->rd_indextuple,
-                                                                               Anum_pg_index_indclass, &isnull);
-               Assert(!isnull);
+               indclassDatum = SysCacheGetAttrNotNull(INDEXRELID,
+                                                                                          index_rel->rd_indextuple,
+                                                                                          Anum_pg_index_indclass);
                indclass = (oidvector *) DatumGetPointer(indclassDatum);
 
                for (i = 0; i < index_form->indnatts; i++)
index a69c1d1e77d794316c39fd83172a0e4f1b039379..cf1156b8427f88af44ab2728a95c18b0d55cf661 100644 (file)
@@ -4311,19 +4311,14 @@ get_qual_for_range(Relation parent, PartitionBoundSpec *spec,
                        Oid                     inhrelid = inhoids[k];
                        HeapTuple       tuple;
                        Datum           datum;
-                       bool            isnull;
                        PartitionBoundSpec *bspec;
 
                        tuple = SearchSysCache1(RELOID, inhrelid);
                        if (!HeapTupleIsValid(tuple))
                                elog(ERROR, "cache lookup failed for relation %u", inhrelid);
 
-                       datum = SysCacheGetAttr(RELOID, tuple,
-                                                                       Anum_pg_class_relpartbound,
-                                                                       &isnull);
-                       if (isnull)
-                               elog(ERROR, "null relpartbound for relation %u", inhrelid);
-
+                       datum = SysCacheGetAttrNotNull(RELOID, tuple,
+                                                                                  Anum_pg_class_relpartbound);
                        bspec = (PartitionBoundSpec *)
                                stringToNode(TextDatumGetCString(datum));
                        if (!IsA(bspec, PartitionBoundSpec))
index 572d9b44643997d4220f0b7bc9d6bb914de49634..54e3bb4aa2746874ec4bada491ccb5619968ce15 100644 (file)
@@ -465,9 +465,8 @@ fetch_statentries_for_relation(Relation pg_statext, Oid relid)
                }
 
                /* decode the stxkind char array into a list of chars */
-               datum = SysCacheGetAttr(STATEXTOID, htup,
-                                                               Anum_pg_statistic_ext_stxkind, &isnull);
-               Assert(!isnull);
+               datum = SysCacheGetAttrNotNull(STATEXTOID, htup,
+                                                                          Anum_pg_statistic_ext_stxkind);
                arr = DatumGetArrayTypeP(datum);
                if (ARR_NDIM(arr) != 1 ||
                        ARR_HASNULL(arr) ||
index 2fb5f64d3686b1bd7972b010260f97d12075823d..48852bf79e24db0c0eacb404b6ce32ad6c93ac0f 100644 (file)
@@ -119,7 +119,6 @@ test_indoption(HeapTuple tuple, int attno, bool guard,
                           bool *res)
 {
        Datum           datum;
-       bool            isnull;
        int2vector *indoption;
        int16           indoption_val;
 
@@ -129,9 +128,7 @@ test_indoption(HeapTuple tuple, int attno, bool guard,
                return true;
        }
 
-       datum = SysCacheGetAttr(INDEXRELID, tuple,
-                                                       Anum_pg_index_indoption, &isnull);
-       Assert(!isnull);
+       datum = SysCacheGetAttrNotNull(INDEXRELID, tuple, Anum_pg_index_indoption);
 
        indoption = ((int2vector *) DatumGetPointer(datum));
        indoption_val = indoption->values[attno - 1];
index 386768ee767c46e873d10ce372943237cf0d9efa..8fc103e42b3567db908862de053b8de4cd0b0826 100644 (file)
@@ -1285,15 +1285,12 @@ lookup_collation_cache(Oid collation, bool set_flags)
                if (collform->collprovider == COLLPROVIDER_LIBC)
                {
                        Datum           datum;
-                       bool            isnull;
                        const char *collcollate;
                        const char *collctype;
 
-                       datum = SysCacheGetAttr(COLLOID, tp, Anum_pg_collation_collcollate, &isnull);
-                       Assert(!isnull);
+                       datum = SysCacheGetAttrNotNull(COLLOID, tp, Anum_pg_collation_collcollate);
                        collcollate = TextDatumGetCString(datum);
-                       datum = SysCacheGetAttr(COLLOID, tp, Anum_pg_collation_collctype, &isnull);
-                       Assert(!isnull);
+                       datum = SysCacheGetAttrNotNull(COLLOID, tp, Anum_pg_collation_collctype);
                        collctype = TextDatumGetCString(datum);
 
                        cache_entry->collate_is_c = ((strcmp(collcollate, "C") == 0) ||
@@ -1577,11 +1574,9 @@ pg_newlocale_from_collation(Oid collid)
                        const char *collctype pg_attribute_unused();
                        locale_t        loc;
 
-                       datum = SysCacheGetAttr(COLLOID, tp, Anum_pg_collation_collcollate, &isnull);
-                       Assert(!isnull);
+                       datum = SysCacheGetAttrNotNull(COLLOID, tp, Anum_pg_collation_collcollate);
                        collcollate = TextDatumGetCString(datum);
-                       datum = SysCacheGetAttr(COLLOID, tp, Anum_pg_collation_collctype, &isnull);
-                       Assert(!isnull);
+                       datum = SysCacheGetAttrNotNull(COLLOID, tp, Anum_pg_collation_collctype);
                        collctype = TextDatumGetCString(datum);
 
                        if (strcmp(collcollate, collctype) == 0)
@@ -1637,8 +1632,7 @@ pg_newlocale_from_collation(Oid collid)
                        const char *iculocstr;
                        const char *icurules;
 
-                       datum = SysCacheGetAttr(COLLOID, tp, Anum_pg_collation_colliculocale, &isnull);
-                       Assert(!isnull);
+                       datum = SysCacheGetAttrNotNull(COLLOID, tp, Anum_pg_collation_colliculocale);
                        iculocstr = TextDatumGetCString(datum);
 
                        datum = SysCacheGetAttr(COLLOID, tp, Anum_pg_collation_collicurules, &isnull);
@@ -1659,8 +1653,7 @@ pg_newlocale_from_collation(Oid collid)
 
                        collversionstr = TextDatumGetCString(datum);
 
-                       datum = SysCacheGetAttr(COLLOID, tp, collform->collprovider == COLLPROVIDER_ICU ? Anum_pg_collation_colliculocale : Anum_pg_collation_collcollate, &isnull);
-                       Assert(!isnull);
+                       datum = SysCacheGetAttrNotNull(COLLOID, tp, collform->collprovider == COLLPROVIDER_ICU ? Anum_pg_collation_colliculocale : Anum_pg_collation_collcollate);
 
                        actual_versionstr = get_collation_actual_version(collform->collprovider,
                                                                                                                         TextDatumGetCString(datum));
index bcb493b56ccb9b3f3533e0b4c92b66cc7960b704..4a98b82f07c2cbe4356d3233da7dea340953ee7b 100644 (file)
@@ -1228,7 +1228,6 @@ pg_get_indexdef_worker(Oid indexrelid, int colno,
        Datum           indcollDatum;
        Datum           indclassDatum;
        Datum           indoptionDatum;
-       bool            isnull;
        oidvector  *indcollation;
        oidvector  *indclass;
        int2vector *indoption;
@@ -1252,19 +1251,16 @@ pg_get_indexdef_worker(Oid indexrelid, int colno,
        Assert(indexrelid == idxrec->indexrelid);
 
        /* Must get indcollation, indclass, and indoption the hard way */
-       indcollDatum = SysCacheGetAttr(INDEXRELID, ht_idx,
-                                                                  Anum_pg_index_indcollation, &isnull);
-       Assert(!isnull);
+       indcollDatum = SysCacheGetAttrNotNull(INDEXRELID, ht_idx,
+                                                                                 Anum_pg_index_indcollation);
        indcollation = (oidvector *) DatumGetPointer(indcollDatum);
 
-       indclassDatum = SysCacheGetAttr(INDEXRELID, ht_idx,
-                                                                       Anum_pg_index_indclass, &isnull);
-       Assert(!isnull);
+       indclassDatum = SysCacheGetAttrNotNull(INDEXRELID, ht_idx,
+                                                                                  Anum_pg_index_indclass);
        indclass = (oidvector *) DatumGetPointer(indclassDatum);
 
-       indoptionDatum = SysCacheGetAttr(INDEXRELID, ht_idx,
-                                                                        Anum_pg_index_indoption, &isnull);
-       Assert(!isnull);
+       indoptionDatum = SysCacheGetAttrNotNull(INDEXRELID, ht_idx,
+                                                                                       Anum_pg_index_indoption);
        indoption = (int2vector *) DatumGetPointer(indoptionDatum);
 
        /*
@@ -1297,9 +1293,8 @@ pg_get_indexdef_worker(Oid indexrelid, int colno,
                Datum           exprsDatum;
                char       *exprsString;
 
-               exprsDatum = SysCacheGetAttr(INDEXRELID, ht_idx,
-                                                                        Anum_pg_index_indexprs, &isnull);
-               Assert(!isnull);
+               exprsDatum = SysCacheGetAttrNotNull(INDEXRELID, ht_idx,
+                                                                                       Anum_pg_index_indexprs);
                exprsString = TextDatumGetCString(exprsDatum);
                indexprs = (List *) stringToNode(exprsString);
                pfree(exprsString);
@@ -1494,9 +1489,8 @@ pg_get_indexdef_worker(Oid indexrelid, int colno,
                        char       *predString;
 
                        /* Convert text string to node tree */
-                       predDatum = SysCacheGetAttr(INDEXRELID, ht_idx,
-                                                                               Anum_pg_index_indpred, &isnull);
-                       Assert(!isnull);
+                       predDatum = SysCacheGetAttrNotNull(INDEXRELID, ht_idx,
+                                                                                          Anum_pg_index_indpred);
                        predString = TextDatumGetCString(predDatum);
                        node = (Node *) stringToNode(predString);
                        pfree(predString);
@@ -1637,12 +1631,10 @@ pg_get_statisticsobj_worker(Oid statextid, bool columns_only, bool missing_ok)
        if (has_exprs)
        {
                Datum           exprsDatum;
-               bool            isnull;
                char       *exprsString;
 
-               exprsDatum = SysCacheGetAttr(STATEXTOID, statexttup,
-                                                                        Anum_pg_statistic_ext_stxexprs, &isnull);
-               Assert(!isnull);
+               exprsDatum = SysCacheGetAttrNotNull(STATEXTOID, statexttup,
+                                                                                       Anum_pg_statistic_ext_stxexprs);
                exprsString = TextDatumGetCString(exprsDatum);
                exprs = (List *) stringToNode(exprsString);
                pfree(exprsString);
@@ -1657,8 +1649,6 @@ pg_get_statisticsobj_worker(Oid statextid, bool columns_only, bool missing_ok)
 
        if (!columns_only)
        {
-               bool            isnull;
-
                nsp = get_namespace_name_or_temp(statextrec->stxnamespace);
                appendStringInfo(&buf, "CREATE STATISTICS %s",
                                                 quote_qualified_identifier(nsp,
@@ -1668,9 +1658,8 @@ pg_get_statisticsobj_worker(Oid statextid, bool columns_only, bool missing_ok)
                 * Decode the stxkind column so that we know which stats types to
                 * print.
                 */
-               datum = SysCacheGetAttr(STATEXTOID, statexttup,
-                                                               Anum_pg_statistic_ext_stxkind, &isnull);
-               Assert(!isnull);
+               datum = SysCacheGetAttrNotNull(STATEXTOID, statexttup,
+                                                                          Anum_pg_statistic_ext_stxkind);
                arr = DatumGetArrayTypeP(datum);
                if (ARR_NDIM(arr) != 1 ||
                        ARR_HASNULL(arr) ||
@@ -1790,7 +1779,6 @@ pg_get_statisticsobjdef_expressions(PG_FUNCTION_ARGS)
        Form_pg_statistic_ext statextrec;
        HeapTuple       statexttup;
        Datum           datum;
-       bool            isnull;
        List       *context;
        ListCell   *lc;
        List       *exprs = NIL;
@@ -1818,10 +1806,8 @@ pg_get_statisticsobjdef_expressions(PG_FUNCTION_ARGS)
        /*
         * Get the statistics expressions, and deparse them into text values.
         */
-       datum = SysCacheGetAttr(STATEXTOID, statexttup,
-                                                       Anum_pg_statistic_ext_stxexprs, &isnull);
-
-       Assert(!isnull);
+       datum = SysCacheGetAttrNotNull(STATEXTOID, statexttup,
+                                                                  Anum_pg_statistic_ext_stxexprs);
        tmp = TextDatumGetCString(datum);
        exprs = (List *) stringToNode(tmp);
        pfree(tmp);
@@ -1897,7 +1883,6 @@ pg_get_partkeydef_worker(Oid relid, int prettyFlags,
        ListCell   *partexpr_item;
        List       *context;
        Datum           datum;
-       bool            isnull;
        StringInfoData buf;
        int                     keyno;
        char       *str;
@@ -1916,14 +1901,12 @@ pg_get_partkeydef_worker(Oid relid, int prettyFlags,
        Assert(form->partrelid == relid);
 
        /* Must get partclass and partcollation the hard way */
-       datum = SysCacheGetAttr(PARTRELID, tuple,
-                                                       Anum_pg_partitioned_table_partclass, &isnull);
-       Assert(!isnull);
+       datum = SysCacheGetAttrNotNull(PARTRELID, tuple,
+                                                                  Anum_pg_partitioned_table_partclass);
        partclass = (oidvector *) DatumGetPointer(datum);
 
-       datum = SysCacheGetAttr(PARTRELID, tuple,
-                                                       Anum_pg_partitioned_table_partcollation, &isnull);
-       Assert(!isnull);
+       datum = SysCacheGetAttrNotNull(PARTRELID, tuple,
+                                                                  Anum_pg_partitioned_table_partcollation);
        partcollation = (oidvector *) DatumGetPointer(datum);
 
 
@@ -1937,9 +1920,8 @@ pg_get_partkeydef_worker(Oid relid, int prettyFlags,
                Datum           exprsDatum;
                char       *exprsString;
 
-               exprsDatum = SysCacheGetAttr(PARTRELID, tuple,
-                                                                        Anum_pg_partitioned_table_partexprs, &isnull);
-               Assert(!isnull);
+               exprsDatum = SysCacheGetAttrNotNull(PARTRELID, tuple,
+                                                                                       Anum_pg_partitioned_table_partexprs);
                exprsString = TextDatumGetCString(exprsDatum);
                partexprs = (List *) stringToNode(exprsString);
 
@@ -2229,11 +2211,8 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
                                appendStringInfoString(&buf, "FOREIGN KEY (");
 
                                /* Fetch and build referencing-column list */
-                               val = SysCacheGetAttr(CONSTROID, tup,
-                                                                         Anum_pg_constraint_conkey, &isnull);
-                               if (isnull)
-                                       elog(ERROR, "null conkey for constraint %u",
-                                                constraintId);
+                               val = SysCacheGetAttrNotNull(CONSTROID, tup,
+                                                                                        Anum_pg_constraint_conkey);
 
                                decompile_column_index_array(val, conForm->conrelid, &buf);
 
@@ -2243,11 +2222,8 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
                                                                                                                NIL));
 
                                /* Fetch and build referenced-column list */
-                               val = SysCacheGetAttr(CONSTROID, tup,
-                                                                         Anum_pg_constraint_confkey, &isnull);
-                               if (isnull)
-                                       elog(ERROR, "null confkey for constraint %u",
-                                                constraintId);
+                               val = SysCacheGetAttrNotNull(CONSTROID, tup,
+                                                                                        Anum_pg_constraint_confkey);
 
                                decompile_column_index_array(val, conForm->confrelid, &buf);
 
@@ -2345,7 +2321,6 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
                case CONSTRAINT_UNIQUE:
                        {
                                Datum           val;
-                               bool            isnull;
                                Oid                     indexId;
                                int                     keyatts;
                                HeapTuple       indtup;
@@ -2368,21 +2343,16 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
                                appendStringInfoChar(&buf, '(');
 
                                /* Fetch and build target column list */
-                               val = SysCacheGetAttr(CONSTROID, tup,
-                                                                         Anum_pg_constraint_conkey, &isnull);
-                               if (isnull)
-                                       elog(ERROR, "null conkey for constraint %u",
-                                                constraintId);
+                               val = SysCacheGetAttrNotNull(CONSTROID, tup,
+                                                                                        Anum_pg_constraint_conkey);
 
                                keyatts = decompile_column_index_array(val, conForm->conrelid, &buf);
 
                                appendStringInfoChar(&buf, ')');
 
                                /* Build including column list (from pg_index.indkeys) */
-                               val = SysCacheGetAttr(INDEXRELID, indtup,
-                                                                         Anum_pg_index_indnatts, &isnull);
-                               if (isnull)
-                                       elog(ERROR, "null indnatts for index %u", indexId);
+                               val = SysCacheGetAttrNotNull(INDEXRELID, indtup,
+                                                                                        Anum_pg_index_indnatts);
                                if (DatumGetInt32(val) > keyatts)
                                {
                                        Datum           cols;
@@ -2392,10 +2362,8 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
 
                                        appendStringInfoString(&buf, " INCLUDE (");
 
-                                       cols = SysCacheGetAttr(INDEXRELID, indtup,
-                                                                                  Anum_pg_index_indkey, &isnull);
-                                       if (isnull)
-                                               elog(ERROR, "null indkey for index %u", indexId);
+                                       cols = SysCacheGetAttrNotNull(INDEXRELID, indtup,
+                                                                                                 Anum_pg_index_indkey);
 
                                        deconstruct_array_builtin(DatumGetArrayTypeP(cols), INT2OID,
                                                                                          &keys, NULL, &nKeys);
@@ -2444,18 +2412,14 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
                case CONSTRAINT_CHECK:
                        {
                                Datum           val;
-                               bool            isnull;
                                char       *conbin;
                                char       *consrc;
                                Node       *expr;
                                List       *context;
 
                                /* Fetch constraint expression in parsetree form */
-                               val = SysCacheGetAttr(CONSTROID, tup,
-                                                                         Anum_pg_constraint_conbin, &isnull);
-                               if (isnull)
-                                       elog(ERROR, "null conbin for constraint %u",
-                                                constraintId);
+                               val = SysCacheGetAttrNotNull(CONSTROID, tup,
+                                                                                        Anum_pg_constraint_conbin);
 
                                conbin = TextDatumGetCString(val);
                                expr = stringToNode(conbin);
@@ -2507,19 +2471,14 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
                        {
                                Oid                     indexOid = conForm->conindid;
                                Datum           val;
-                               bool            isnull;
                                Datum      *elems;
                                int                     nElems;
                                int                     i;
                                Oid                *operators;
 
                                /* Extract operator OIDs from the pg_constraint tuple */
-                               val = SysCacheGetAttr(CONSTROID, tup,
-                                                                         Anum_pg_constraint_conexclop,
-                                                                         &isnull);
-                               if (isnull)
-                                       elog(ERROR, "null conexclop for constraint %u",
-                                                constraintId);
+                               val = SysCacheGetAttrNotNull(CONSTROID, tup,
+                                                                                        Anum_pg_constraint_conexclop);
 
                                deconstruct_array_builtin(DatumGetArrayTypeP(val), OIDOID,
                                                                                  &elems, NULL, &nElems);
@@ -3088,9 +3047,7 @@ pg_get_functiondef(PG_FUNCTION_ARGS)
                        appendStringInfoString(&buf, ", "); /* assume prosrc isn't null */
                }
 
-               tmp = SysCacheGetAttr(PROCOID, proctup, Anum_pg_proc_prosrc, &isnull);
-               if (isnull)
-                       elog(ERROR, "null prosrc");
+               tmp = SysCacheGetAttrNotNull(PROCOID, proctup, Anum_pg_proc_prosrc);
                prosrc = TextDatumGetCString(tmp);
 
                /*
@@ -3512,7 +3469,6 @@ print_function_sqlbody(StringInfo buf, HeapTuple proctup)
        char       *argmodes;
        deparse_namespace dpns = {0};
        Datum           tmp;
-       bool            isnull;
        Node       *n;
 
        dpns.funcname = pstrdup(NameStr(((Form_pg_proc) GETSTRUCT(proctup))->proname));
@@ -3521,8 +3477,7 @@ print_function_sqlbody(StringInfo buf, HeapTuple proctup)
        dpns.numargs = numargs;
        dpns.argnames = argnames;
 
-       tmp = SysCacheGetAttr(PROCOID, proctup, Anum_pg_proc_prosqlbody, &isnull);
-       Assert(!isnull);
+       tmp = SysCacheGetAttrNotNull(PROCOID, proctup, Anum_pg_proc_prosqlbody);
        n = stringToNode(TextDatumGetCString(tmp));
 
        if (IsA(n, List))
index c07382051d66a2fc31adab738ed7f2f9207f26a0..c7607895cddccaf33c833022a8f02d464f84cd63 100644 (file)
@@ -3195,7 +3195,6 @@ get_attstatsslot(AttStatsSlot *sslot, HeapTuple statstuple,
        Form_pg_statistic stats = (Form_pg_statistic) GETSTRUCT(statstuple);
        int                     i;
        Datum           val;
-       bool            isnull;
        ArrayType  *statarray;
        Oid                     arrayelemtype;
        int                     narrayelem;
@@ -3219,11 +3218,8 @@ get_attstatsslot(AttStatsSlot *sslot, HeapTuple statstuple,
 
        if (flags & ATTSTATSSLOT_VALUES)
        {
-               val = SysCacheGetAttr(STATRELATTINH, statstuple,
-                                                         Anum_pg_statistic_stavalues1 + i,
-                                                         &isnull);
-               if (isnull)
-                       elog(ERROR, "stavalues is null");
+               val = SysCacheGetAttrNotNull(STATRELATTINH, statstuple,
+                                                                        Anum_pg_statistic_stavalues1 + i);
 
                /*
                 * Detoast the array if needed, and in any case make a copy that's
@@ -3267,11 +3263,8 @@ get_attstatsslot(AttStatsSlot *sslot, HeapTuple statstuple,
 
        if (flags & ATTSTATSSLOT_NUMBERS)
        {
-               val = SysCacheGetAttr(STATRELATTINH, statstuple,
-                                                         Anum_pg_statistic_stanumbers1 + i,
-                                                         &isnull);
-               if (isnull)
-                       elog(ERROR, "stanumbers is null");
+               val = SysCacheGetAttrNotNull(STATRELATTINH, statstuple,
+                                                                        Anum_pg_statistic_stanumbers1 + i);
 
                /*
                 * Detoast the array if needed, and in any case make a copy that's
@@ -3479,7 +3472,6 @@ get_index_column_opclass(Oid index_oid, int attno)
        HeapTuple       tuple;
        Form_pg_index rd_index;
        Datum           datum;
-       bool            isnull;
        oidvector  *indclass;
        Oid                     opclass;
 
@@ -3501,10 +3493,7 @@ get_index_column_opclass(Oid index_oid, int attno)
                return InvalidOid;
        }
 
-       datum = SysCacheGetAttr(INDEXRELID, tuple,
-                                                       Anum_pg_index_indclass, &isnull);
-       Assert(!isnull);
-
+       datum = SysCacheGetAttrNotNull(INDEXRELID, tuple, Anum_pg_index_indclass);
        indclass = ((oidvector *) DatumGetPointer(datum));
 
        Assert(attno <= indclass->dim1);
index 4f53d47233358915e5ae17415c74031778eab1f1..5f3516ad0c2459c687f87175c6592425e7ce5af5 100644 (file)
@@ -130,15 +130,13 @@ RelationBuildPartitionKey(Relation relation)
 
        /* But use the hard way to retrieve further variable-length attributes */
        /* Operator class */
-       datum = SysCacheGetAttr(PARTRELID, tuple,
-                                                       Anum_pg_partitioned_table_partclass, &isnull);
-       Assert(!isnull);
+       datum = SysCacheGetAttrNotNull(PARTRELID, tuple,
+                                                                  Anum_pg_partitioned_table_partclass);
        opclass = (oidvector *) DatumGetPointer(datum);
 
        /* Collation */
-       datum = SysCacheGetAttr(PARTRELID, tuple,
-                                                       Anum_pg_partitioned_table_partcollation, &isnull);
-       Assert(!isnull);
+       datum = SysCacheGetAttrNotNull(PARTRELID, tuple,
+                                                                  Anum_pg_partitioned_table_partcollation);
        collation = (oidvector *) DatumGetPointer(datum);
 
        /* Expressions */
index 94abede512b3337044102d651fff2d4bb5d0bff7..4e4a34bde800340ad75d28b5f11b6b732f2899ed 100644 (file)
@@ -77,6 +77,7 @@
 #include "catalog/pg_user_mapping.h"
 #include "lib/qunique.h"
 #include "utils/catcache.h"
+#include "utils/lsyscache.h"
 #include "utils/rel.h"
 #include "utils/syscache.h"
 
@@ -1099,6 +1100,32 @@ SysCacheGetAttr(int cacheId, HeapTuple tup,
                                                isNull);
 }
 
+/*
+ * SysCacheGetAttrNotNull
+ *
+ * As above, a version of SysCacheGetAttr which knows that the attr cannot
+ * be NULL.
+ */
+Datum
+SysCacheGetAttrNotNull(int cacheId, HeapTuple tup,
+                                          AttrNumber attributeNumber)
+{
+       bool            isnull;
+       Datum           attr;
+
+       attr = SysCacheGetAttr(cacheId, tup, attributeNumber, &isnull);
+
+       if (isnull)
+       {
+               elog(ERROR,
+                        "unexpected null value in cached tuple for catalog %s column %s",
+                        get_rel_name(cacheinfo[cacheId].reloid),
+                        NameStr(TupleDescAttr(SysCache[cacheId]->cc_tupdesc, attributeNumber - 1)->attname));
+       }
+
+       return attr;
+}
+
 /*
  * GetSysCacheHashValue
  *
index 3f64161760e019a928b4d5496a27db8e97f27c79..f72dd25efa5919e37dca7f59cdb0729f4d245696 100644 (file)
@@ -151,7 +151,6 @@ fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt,
        HeapTuple       procedureTuple;
        Form_pg_proc procedureStruct;
        Datum           prosrcdatum;
-       bool            isnull;
        char       *prosrc;
 
        /*
@@ -227,10 +226,8 @@ fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt,
                         * internal function is stored in prosrc (it doesn't have to be
                         * the same as the name of the alias!)
                         */
-                       prosrcdatum = SysCacheGetAttr(PROCOID, procedureTuple,
-                                                                                 Anum_pg_proc_prosrc, &isnull);
-                       if (isnull)
-                               elog(ERROR, "null prosrc");
+                       prosrcdatum = SysCacheGetAttrNotNull(PROCOID, procedureTuple,
+                                                                                                Anum_pg_proc_prosrc);
                        prosrc = TextDatumGetCString(prosrcdatum);
                        fbp = fmgr_lookupByName(prosrc);
                        if (fbp == NULL)
@@ -285,7 +282,6 @@ fmgr_symbol(Oid functionId, char **mod, char **fn)
 {
        HeapTuple       procedureTuple;
        Form_pg_proc procedureStruct;
-       bool            isnull;
        Datum           prosrcattr;
        Datum           probinattr;
 
@@ -308,25 +304,19 @@ fmgr_symbol(Oid functionId, char **mod, char **fn)
        switch (procedureStruct->prolang)
        {
                case INTERNALlanguageId:
-                       prosrcattr = SysCacheGetAttr(PROCOID, procedureTuple,
-                                                                                Anum_pg_proc_prosrc, &isnull);
-                       if (isnull)
-                               elog(ERROR, "null prosrc");
+                       prosrcattr = SysCacheGetAttrNotNull(PROCOID, procedureTuple,
+                                                                                               Anum_pg_proc_prosrc);
 
                        *mod = NULL;            /* core binary */
                        *fn = TextDatumGetCString(prosrcattr);
                        break;
 
                case ClanguageId:
-                       prosrcattr = SysCacheGetAttr(PROCOID, procedureTuple,
-                                                                                Anum_pg_proc_prosrc, &isnull);
-                       if (isnull)
-                               elog(ERROR, "null prosrc for C function %u", functionId);
+                       prosrcattr = SysCacheGetAttrNotNull(PROCOID, procedureTuple,
+                                                                                               Anum_pg_proc_prosrc);
 
-                       probinattr = SysCacheGetAttr(PROCOID, procedureTuple,
-                                                                                Anum_pg_proc_probin, &isnull);
-                       if (isnull)
-                               elog(ERROR, "null probin for C function %u", functionId);
+                       probinattr = SysCacheGetAttrNotNull(PROCOID, procedureTuple,
+                                                                                               Anum_pg_proc_probin);
 
                        /*
                         * No need to check symbol presence / API version here, already
@@ -361,7 +351,6 @@ fmgr_info_C_lang(Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple)
        CFuncHashTabEntry *hashentry;
        PGFunction      user_fn;
        const Pg_finfo_record *inforec;
-       bool            isnull;
 
        /*
         * See if we have the function address cached already
@@ -385,16 +374,12 @@ fmgr_info_C_lang(Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple)
                 * While in general these columns might be null, that's not allowed
                 * for C-language functions.
                 */
-               prosrcattr = SysCacheGetAttr(PROCOID, procedureTuple,
-                                                                        Anum_pg_proc_prosrc, &isnull);
-               if (isnull)
-                       elog(ERROR, "null prosrc for C function %u", functionId);
+               prosrcattr = SysCacheGetAttrNotNull(PROCOID, procedureTuple,
+                                                                                       Anum_pg_proc_prosrc);
                prosrcstring = TextDatumGetCString(prosrcattr);
 
-               probinattr = SysCacheGetAttr(PROCOID, procedureTuple,
-                                                                        Anum_pg_proc_probin, &isnull);
-               if (isnull)
-                       elog(ERROR, "null probin for C function %u", functionId);
+               probinattr = SysCacheGetAttrNotNull(PROCOID, procedureTuple,
+                                                                                       Anum_pg_proc_probin);
                probinstring = TextDatumGetCString(probinattr);
 
                /* Look up the function itself */
index 217835d590bedde3cbc1026c6583a66f90761704..24683bb608e6f7ab2fa07b99886e3d0aef86c16f 100644 (file)
@@ -1602,7 +1602,6 @@ get_func_result_name(Oid functionId)
        HeapTuple       procTuple;
        Datum           proargmodes;
        Datum           proargnames;
-       bool            isnull;
        ArrayType  *arr;
        int                     numargs;
        char       *argmodes;
@@ -1623,14 +1622,10 @@ get_func_result_name(Oid functionId)
        else
        {
                /* Get the data out of the tuple */
-               proargmodes = SysCacheGetAttr(PROCOID, procTuple,
-                                                                         Anum_pg_proc_proargmodes,
-                                                                         &isnull);
-               Assert(!isnull);
-               proargnames = SysCacheGetAttr(PROCOID, procTuple,
-                                                                         Anum_pg_proc_proargnames,
-                                                                         &isnull);
-               Assert(!isnull);
+               proargmodes = SysCacheGetAttrNotNull(PROCOID, procTuple,
+                                                                                        Anum_pg_proc_proargmodes);
+               proargnames = SysCacheGetAttrNotNull(PROCOID, procTuple,
+                                                                                        Anum_pg_proc_proargnames);
 
                /*
                 * We expect the arrays to be 1-D arrays of the right types; verify
@@ -1717,14 +1712,10 @@ build_function_result_tupdesc_t(HeapTuple procTuple)
                return NULL;
 
        /* Get the data out of the tuple */
-       proallargtypes = SysCacheGetAttr(PROCOID, procTuple,
-                                                                        Anum_pg_proc_proallargtypes,
-                                                                        &isnull);
-       Assert(!isnull);
-       proargmodes = SysCacheGetAttr(PROCOID, procTuple,
-                                                                 Anum_pg_proc_proargmodes,
-                                                                 &isnull);
-       Assert(!isnull);
+       proallargtypes = SysCacheGetAttrNotNull(PROCOID, procTuple,
+                                                                                       Anum_pg_proc_proallargtypes);
+       proargmodes = SysCacheGetAttrNotNull(PROCOID, procTuple,
+                                                                                Anum_pg_proc_proargmodes);
        proargnames = SysCacheGetAttr(PROCOID, procTuple,
                                                                  Anum_pg_proc_proargnames,
                                                                  &isnull);
index 31d6a054260ff25c9a5c87e981b5a776ed7d222f..60feae0f1b14bcc1f5db1259362c7304d43f8053 100644 (file)
@@ -398,11 +398,9 @@ CheckMyDatabase(const char *name, bool am_superuser, bool override_allow_connect
                                        PGC_BACKEND, PGC_S_DYNAMIC_DEFAULT);
 
        /* assign locale variables */
-       datum = SysCacheGetAttr(DATABASEOID, tup, Anum_pg_database_datcollate, &isnull);
-       Assert(!isnull);
+       datum = SysCacheGetAttrNotNull(DATABASEOID, tup, Anum_pg_database_datcollate);
        collate = TextDatumGetCString(datum);
-       datum = SysCacheGetAttr(DATABASEOID, tup, Anum_pg_database_datctype, &isnull);
-       Assert(!isnull);
+       datum = SysCacheGetAttrNotNull(DATABASEOID, tup, Anum_pg_database_datctype);
        ctype = TextDatumGetCString(datum);
 
        if (pg_perm_setlocale(LC_COLLATE, collate) == NULL)
@@ -427,8 +425,7 @@ CheckMyDatabase(const char *name, bool am_superuser, bool override_allow_connect
        {
                char       *icurules;
 
-               datum = SysCacheGetAttr(DATABASEOID, tup, Anum_pg_database_daticulocale, &isnull);
-               Assert(!isnull);
+               datum = SysCacheGetAttrNotNull(DATABASEOID, tup, Anum_pg_database_daticulocale);
                iculocale = TextDatumGetCString(datum);
 
                datum = SysCacheGetAttr(DATABASEOID, tup, Anum_pg_database_daticurules, &isnull);
index d5d50ceab490f28434adf3b2ca637e40bc2fbc11..67ea6e4945275b062e38f9b7e30585e59c1f8603 100644 (file)
@@ -157,6 +157,9 @@ extern HeapTuple SearchSysCacheCopyAttNum(Oid relid, int16 attnum);
 extern Datum SysCacheGetAttr(int cacheId, HeapTuple tup,
                                                         AttrNumber attributeNumber, bool *isNull);
 
+extern Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup,
+                                                                       AttrNumber attributeNumber);
+
 extern uint32 GetSysCacheHashValue(int cacheId,
                                                                   Datum key1, Datum key2, Datum key3, Datum key4);
 
index 8143ae40a01013290c80ce88d39b8e75206feb28..d7d9c1bee3726e5380643028e7da922d50aef980 100644 (file)
@@ -2915,10 +2915,8 @@ compile_plperl_function(Oid fn_oid, bool is_trigger, bool is_event_trigger)
                 * we do not use a named subroutine so that we can call directly
                 * through the reference.
                 ************************************************************/
-               prosrcdatum = SysCacheGetAttr(PROCOID, procTup,
-                                                                         Anum_pg_proc_prosrc, &isnull);
-               if (isnull)
-                       elog(ERROR, "null prosrc");
+               prosrcdatum = SysCacheGetAttrNotNull(PROCOID, procTup,
+                                                                                        Anum_pg_proc_prosrc);
                proc_source = TextDatumGetCString(prosrcdatum);
 
                /************************************************************
index 7db912fd18b74bfd693a6e6fa5c12162e6620df9..a341cde2c142052fbbae9bf2db48ddbc899a75c0 100644 (file)
@@ -271,7 +271,6 @@ do_compile(FunctionCallInfo fcinfo,
        bool            is_dml_trigger = CALLED_AS_TRIGGER(fcinfo);
        bool            is_event_trigger = CALLED_AS_EVENT_TRIGGER(fcinfo);
        Datum           prosrcdatum;
-       bool            isnull;
        char       *proc_source;
        HeapTuple       typeTup;
        Form_pg_type typeStruct;
@@ -296,10 +295,7 @@ do_compile(FunctionCallInfo fcinfo,
         * cannot be invoked recursively, so there's no need to save and restore
         * the static variables used here.
         */
-       prosrcdatum = SysCacheGetAttr(PROCOID, procTup,
-                                                                 Anum_pg_proc_prosrc, &isnull);
-       if (isnull)
-               elog(ERROR, "null prosrc");
+       prosrcdatum = SysCacheGetAttrNotNull(PROCOID, procTup, Anum_pg_proc_prosrc);
        proc_source = TextDatumGetCString(prosrcdatum);
        plpgsql_scanner_init(proc_source);
 
index 494f109b3232004583dfecf74b4c34614155ebf6..79b6ef6a44878f1a602aa08fbaf2c9b6b9175243 100644 (file)
@@ -324,10 +324,8 @@ PLy_procedure_create(HeapTuple procTup, Oid fn_oid, bool is_trigger)
                /*
                 * get the text of the function.
                 */
-               prosrcdatum = SysCacheGetAttr(PROCOID, procTup,
-                                                                         Anum_pg_proc_prosrc, &isnull);
-               if (isnull)
-                       elog(ERROR, "null prosrc");
+               prosrcdatum = SysCacheGetAttrNotNull(PROCOID, procTup,
+                                                                                        Anum_pg_proc_prosrc);
                procSource = TextDatumGetCString(prosrcdatum);
 
                PLy_procedure_compile(proc, procSource);
index 499a9eaba811f00f36193ada27aa8ed68d77c6d8..e8f9d7b289c687733f94abe1e00c0365cca3965f 100644 (file)
@@ -1454,7 +1454,6 @@ compile_pltcl_function(Oid fn_oid, Oid tgreloid,
                Form_pg_type typeStruct;
                char            proc_internal_args[33 * FUNC_MAX_ARGS];
                Datum           prosrcdatum;
-               bool            isnull;
                char       *proc_source;
                char            buf[48];
                Tcl_Interp *interp;
@@ -1673,10 +1672,8 @@ compile_pltcl_function(Oid fn_oid, Oid tgreloid,
                /************************************************************
                 * Add user's function definition to proc body
                 ************************************************************/
-               prosrcdatum = SysCacheGetAttr(PROCOID, procTup,
-                                                                         Anum_pg_proc_prosrc, &isnull);
-               if (isnull)
-                       elog(ERROR, "null prosrc");
+               prosrcdatum = SysCacheGetAttrNotNull(PROCOID, procTup,
+                                                                                        Anum_pg_proc_prosrc);
                proc_source = TextDatumGetCString(prosrcdatum);
                UTF_BEGIN;
                Tcl_DStringAppend(&proc_internal_body, UTF_E2U(proc_source), -1);