mirror of
https://github.com/postgres/postgres.git
synced 2025-12-22 17:42:17 +03:00
Add SysCacheGetAttrNotNull for guaranteed not-null attrs
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 <tgl@sss.pgh.pa.us> Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com> Reviewed-by: David Rowley <dgrowleyml@gmail.com> Discussion: https://postgr.es/m/AD76405E-DB45-46B6-941F-17B1EB3A9076@yesql.se
This commit is contained in:
@@ -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];
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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))
|
||||
|
||||
21
src/backend/utils/cache/lsyscache.c
vendored
21
src/backend/utils/cache/lsyscache.c
vendored
@@ -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);
|
||||
|
||||
10
src/backend/utils/cache/partcache.c
vendored
10
src/backend/utils/cache/partcache.c
vendored
@@ -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 */
|
||||
|
||||
27
src/backend/utils/cache/syscache.c
vendored
27
src/backend/utils/cache/syscache.c
vendored
@@ -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
|
||||
*
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user