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/parser/parse_utilcmd.c | |
parent | e33967b13bbc6e4e1c1b5e9ecd1c45148cffcc53 (diff) | |
download | postgresql-d435f15fff3cf3cf5d6cfcfd63e21acc0f737829.tar.gz postgresql-d435f15fff3cf3cf5d6cfcfd63e21acc0f737829.zip |
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/parser/parse_utilcmd.c')
-rw-r--r-- | src/backend/parser/parse_utilcmd.c | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index f9218f48aa7..15a1dab8c5a 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -1562,15 +1562,12 @@ generateClonedIndexStmt(RangeVar *heapRel, Relation source_idx, amrec = (Form_pg_am) GETSTRUCT(ht_am); /* Extract indcollation from the pg_index tuple */ - datum = SysCacheGetAttr(INDEXRELID, ht_idx, - Anum_pg_index_indcollation, &isnull); - Assert(!isnull); + datum = SysCacheGetAttrNotNull(INDEXRELID, ht_idx, + Anum_pg_index_indcollation); indcollation = (oidvector *) DatumGetPointer(datum); /* Extract indclass from the pg_index tuple */ - datum = SysCacheGetAttr(INDEXRELID, ht_idx, - Anum_pg_index_indclass, &isnull); - Assert(!isnull); + datum = SysCacheGetAttrNotNull(INDEXRELID, ht_idx, Anum_pg_index_indclass); indclass = (oidvector *) DatumGetPointer(datum); /* Begin building the IndexStmt */ @@ -1641,13 +1638,8 @@ generateClonedIndexStmt(RangeVar *heapRel, Relation source_idx, Assert(conrec->contype == CONSTRAINT_EXCLUSION); /* Extract operator OIDs from the pg_constraint tuple */ - datum = SysCacheGetAttr(CONSTROID, ht_constr, - Anum_pg_constraint_conexclop, - &isnull); - if (isnull) - elog(ERROR, "null conexclop for constraint %u", - constraintId); - + datum = SysCacheGetAttrNotNull(CONSTROID, ht_constr, + Anum_pg_constraint_conexclop); deconstruct_array_builtin(DatumGetArrayTypeP(datum), OIDOID, &elems, NULL, &nElems); for (i = 0; i < nElems; i++) @@ -1898,9 +1890,8 @@ generateClonedExtStatsStmt(RangeVar *heapRel, Oid heapRelid, statsrec = (Form_pg_statistic_ext) GETSTRUCT(ht_stats); /* Determine which statistics types exist */ - datum = SysCacheGetAttr(STATEXTOID, ht_stats, - Anum_pg_statistic_ext_stxkind, &isnull); - Assert(!isnull); + datum = SysCacheGetAttrNotNull(STATEXTOID, ht_stats, + Anum_pg_statistic_ext_stxkind); arr = DatumGetArrayTypeP(datum); if (ARR_NDIM(arr) != 1 || ARR_HASNULL(arr) || @@ -2228,7 +2219,6 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt) Form_pg_index index_form; oidvector *indclass; Datum indclassDatum; - bool isnull; int i; /* Grammar should not allow this with explicit column list */ @@ -2327,9 +2317,9 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt) parser_errposition(cxt->pstate, constraint->location))); /* Must get indclass the hard way */ - indclassDatum = SysCacheGetAttr(INDEXRELID, index_rel->rd_indextuple, - Anum_pg_index_indclass, &isnull); - Assert(!isnull); + indclassDatum = SysCacheGetAttrNotNull(INDEXRELID, + index_rel->rd_indextuple, + Anum_pg_index_indclass); indclass = (oidvector *) DatumGetPointer(indclassDatum); for (i = 0; i < index_form->indnatts; i++) |