diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2025-03-28 10:49:15 +0100 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2025-03-28 10:49:15 +0100 |
commit | 747ddd38cbf6d32bca496e69c1efb2ae4fe333cc (patch) | |
tree | a1e8bbcbf2514befee01f50076363c448a4a05ae /src/backend/executor/execMain.c | |
parent | 9a9ead1105482fc292eccf707697da2ebcc578e5 (diff) | |
download | postgresql-747ddd38cbf6d32bca496e69c1efb2ae4fe333cc.tar.gz postgresql-747ddd38cbf6d32bca496e69c1efb2ae4fe333cc.zip |
Modernize some code a bit
Modernize code in ExecRelCheck() and ExecConstraints() a bit,
preparing the way for some new code.
Co-authored-by: jian he <jian.universality@gmail.com>
Reviewed-by: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Navneet Kumar <thanit3111@gmail.com>
Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://postgr.es/m/CACJufxHArQysbDkWFmvK+D1TPHQWWTxWN15cMuUaTYX3xhQXgg@mail.gmail.com
Diffstat (limited to 'src/backend/executor/execMain.c')
-rw-r--r-- | src/backend/executor/execMain.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index 1cd4dbd2b90..a2271275571 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -1855,7 +1855,6 @@ ExecRelCheck(ResultRelInfo *resultRelInfo, ConstrCheck *check = rel->rd_att->constr->check; ExprContext *econtext; MemoryContext oldContext; - int i; /* * CheckConstraintFetch let this pass with only a warning, but now we @@ -1874,9 +1873,8 @@ ExecRelCheck(ResultRelInfo *resultRelInfo, if (resultRelInfo->ri_CheckConstraintExprs == NULL) { oldContext = MemoryContextSwitchTo(estate->es_query_cxt); - resultRelInfo->ri_CheckConstraintExprs = - (ExprState **) palloc0(ncheck * sizeof(ExprState *)); - for (i = 0; i < ncheck; i++) + resultRelInfo->ri_CheckConstraintExprs = palloc0_array(ExprState *, ncheck); + for (int i = 0; i < ncheck; i++) { Expr *checkconstr; @@ -1902,7 +1900,7 @@ ExecRelCheck(ResultRelInfo *resultRelInfo, econtext->ecxt_scantuple = slot; /* And evaluate the constraints */ - for (i = 0; i < ncheck; i++) + for (int i = 0; i < ncheck; i++) { ExprState *checkconstr = resultRelInfo->ri_CheckConstraintExprs[i]; @@ -2061,16 +2059,16 @@ ExecConstraints(ResultRelInfo *resultRelInfo, Assert(constr); /* we should not be called otherwise */ + /* + * Verify not-null constraints. + */ if (constr->has_not_null) { - int natts = tupdesc->natts; - int attrChk; - - for (attrChk = 1; attrChk <= natts; attrChk++) + for (AttrNumber attnum = 1; attnum <= tupdesc->natts; attnum++) { - Form_pg_attribute att = TupleDescAttr(tupdesc, attrChk - 1); + Form_pg_attribute att = TupleDescAttr(tupdesc, attnum - 1); - if (att->attnotnull && slot_attisnull(slot, attrChk)) + if (att->attnotnull && slot_attisnull(slot, attnum)) { char *val_desc; Relation orig_rel = rel; @@ -2115,16 +2113,19 @@ ExecConstraints(ResultRelInfo *resultRelInfo, 64); ereport(ERROR, - (errcode(ERRCODE_NOT_NULL_VIOLATION), - errmsg("null value in column \"%s\" of relation \"%s\" violates not-null constraint", - NameStr(att->attname), - RelationGetRelationName(orig_rel)), - val_desc ? errdetail("Failing row contains %s.", val_desc) : 0, - errtablecol(orig_rel, attrChk))); + errcode(ERRCODE_NOT_NULL_VIOLATION), + errmsg("null value in column \"%s\" of relation \"%s\" violates not-null constraint", + NameStr(att->attname), + RelationGetRelationName(orig_rel)), + val_desc ? errdetail("Failing row contains %s.", val_desc) : 0, + errtablecol(orig_rel, attnum)); } } } + /* + * Verify check constraints. + */ if (rel->rd_rel->relchecks > 0) { const char *failed; |