diff options
author | Daniel Gustafsson <dgustafsson@postgresql.org> | 2023-03-25 22:49:33 +0100 |
---|---|---|
committer | Daniel Gustafsson <dgustafsson@postgresql.org> | 2023-03-25 22:49:33 +0100 |
commit | d435f15fff3cf3cf5d6cfcfd63e21acc0f737829 (patch) | |
tree | 9be0836e44c3b6809bf2f6910e9fd4a45ef1f217 /src/backend/utils/cache/lsyscache.c | |
parent | e33967b13bbc6e4e1c1b5e9ecd1c45148cffcc53 (diff) |
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
Diffstat (limited to 'src/backend/utils/cache/lsyscache.c')
-rw-r--r-- | src/backend/utils/cache/lsyscache.c | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index c07382051d6..c7607895cdd 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -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); |