summaryrefslogtreecommitdiff
path: root/src/backend/commands/tablecmds.c
diff options
context:
space:
mode:
authorDaniel Gustafsson <dgustafsson@postgresql.org>2023-03-25 22:49:33 +0100
committerDaniel Gustafsson <dgustafsson@postgresql.org>2023-03-25 22:49:33 +0100
commitd435f15fff3cf3cf5d6cfcfd63e21acc0f737829 (patch)
tree9be0836e44c3b6809bf2f6910e9fd4a45ef1f217 /src/backend/commands/tablecmds.c
parente33967b13bbc6e4e1c1b5e9ecd1c45148cffcc53 (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/commands/tablecmds.c')
-rw-r--r--src/backend/commands/tablecmds.c27
1 files changed, 8 insertions, 19 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 9a877f90d36..9b0a0142d3b 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -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() */