mirror of
https://github.com/postgres/postgres.git
synced 2025-11-24 00:23:06 +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:
@@ -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 ||
|
||||
|
||||
Reference in New Issue
Block a user