1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-15 05:46:52 +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:
Daniel Gustafsson
2023-03-25 22:49:33 +01:00
parent e33967b13b
commit d435f15fff
38 changed files with 232 additions and 452 deletions

View 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);