From ccd36ac6a786b1a29356e986e61a8c9a3fdf9cb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Herrera?= Date: Wed, 19 Mar 2025 12:04:54 +0100 Subject: [PATCH 2/3] pgindent --- src/backend/commands/tablecmds.c | 18 +++++++++------ src/backend/executor/execMain.c | 39 +++++++++++++++++--------------- src/include/executor/executor.h | 8 +++---- src/include/nodes/execnodes.h | 1 + 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 07aa719065d..e49a4a4ad7d 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -6216,7 +6216,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap) List *dropped_attrs = NIL; ListCell *lc; Snapshot snapshot; - ResultRelInfo *rInfo = NULL; + ResultRelInfo *rInfo = NULL; MemoryContext oldcontext; if (list_length(all_virtual_nns) > 0) @@ -6227,7 +6227,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap) rInfo = makeNode(ResultRelInfo); InitResultRelInfo(rInfo, oldrel, - 0, /* dummy rangetable index */ + 0, /* dummy rangetable index */ NULL, estate->es_instrument); MemoryContextSwitchTo(oldcontext); @@ -6314,7 +6314,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap) while (table_scan_getnextslot(scan, ForwardScanDirection, oldslot)) { TupleTableSlot *insertslot; - bool virtual_notnull_check = false; + bool virtual_notnull_check = false; if (tab->rewrite > 0) { @@ -6406,7 +6406,10 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap) { Form_pg_attribute attr = TupleDescAttr(newTupDesc, attn); - /* virtual generated column not null constraint handled below */ + /* + * virtual generated column not null constraint handled + * below + */ if (attr->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL) { @@ -6425,7 +6428,8 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap) if (virtual_notnull_check) { - int attnum = -1; + int attnum = -1; + Assert(list_length(all_virtual_nns) > 0); attnum = ExecRelCheckGenVirtualNotNull(rInfo, insertslot, @@ -6438,8 +6442,8 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap) ereport(ERROR, errcode(ERRCODE_NOT_NULL_VIOLATION), errmsg("column \"%s\" of relation \"%s\" contains null values", - NameStr(attr->attname), - RelationGetRelationName(oldrel)), + NameStr(attr->attname), + RelationGetRelationName(oldrel)), errtablecol(oldrel, attnum)); } } diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index 5852f272b44..32e1978a724 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -1886,8 +1886,8 @@ ExecRelCheckGenVirtualNotNull(ResultRelInfo *resultRelInfo, TupleTableSlot *slot /* * We will use the EState's per-tuple context for evaluating virtual - * generated column not null constraint expressions (creating it if it's not - * already there). + * generated column not null constraint expressions (creating it if it's + * not already there). */ econtext = GetPerTupleExprContext(estate); @@ -1899,6 +1899,7 @@ ExecRelCheckGenVirtualNotNull(ResultRelInfo *resultRelInfo, TupleTableSlot *slot foreach_int(attnum, all_virtual_nns) { ExprState *exprstate = resultRelInfo->ri_GeneratedNotNullExprs[i++]; + if (exprstate && !ExecCheck(exprstate, econtext)) return attnum; } @@ -2123,12 +2124,11 @@ NotNullViolationErrorReport(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, Assert(attrChk > 0); /* - * If the tuple has been routed, it's been converted to the - * partition's rowtype, which might differ from the root - * table's. We must convert it back to the root table's - * rowtype so that val_desc shown error message matches the - * input tuple. - */ + * If the tuple has been routed, it's been converted to the partition's + * rowtype, which might differ from the root table's. We must convert it + * back to the root table's rowtype so that val_desc shown error message + * matches the input tuple. + */ if (resultRelInfo->ri_RootResultRelInfo) { ResultRelInfo *rootrel = resultRelInfo->ri_RootResultRelInfo; @@ -2141,9 +2141,9 @@ NotNullViolationErrorReport(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, false); /* - * Partition-specific slot's tupdesc can't be changed, so - * allocate a new one. - */ + * Partition-specific slot's tupdesc can't be changed, so allocate a + * new one. + */ if (map != NULL) slot = execute_attr_map_slot(map, slot, MakeTupleTableSlot(tupdesc, &TTSOpsVirtual)); @@ -2163,10 +2163,10 @@ NotNullViolationErrorReport(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, 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)); + NameStr(att->attname), + RelationGetRelationName(orig_rel)), + val_desc ? errdetail("Failing row contains %s.", val_desc) : 0, + errtablecol(orig_rel, attrChk)); } /* @@ -2191,11 +2191,11 @@ ExecConstraints(ResultRelInfo *resultRelInfo, Form_pg_attribute att; int natts; int attnum; - List *all_virtual_nns = NIL; + List *all_virtual_nns = NIL; bool virtual_notnull_check = false; Assert(constr); /* we should not be called otherwise */ - natts = tupdesc->natts; + natts = tupdesc->natts; if (constr->has_not_null) { @@ -2229,7 +2229,10 @@ ExecConstraints(ResultRelInfo *resultRelInfo, attnum = -1; attnum = ExecRelCheckGenVirtualNotNull(resultRelInfo, slot, estate, all_virtual_nns); - /* constraint evaulation return falsem do error report, also make an Assert */ + /* + * constraint evaulation return falsem do error report, also make an + * Assert + */ if (attnum > 0) { att = TupleDescAttr(tupdesc, attnum - 1); diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h index 549e8c9b095..7cfedd14c9f 100644 --- a/src/include/executor/executor.h +++ b/src/include/executor/executor.h @@ -220,10 +220,10 @@ extern ResultRelInfo *ExecGetTriggerResultRel(EState *estate, Oid relid, extern List *ExecGetAncestorResultRels(EState *estate, ResultRelInfo *resultRelInfo); extern void ExecConstraints(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate); -extern int ExecRelCheckGenVirtualNotNull(ResultRelInfo *resultRelInfo, - TupleTableSlot *slot, - EState *estate, - List *all_virtual_nns); +extern int ExecRelCheckGenVirtualNotNull(ResultRelInfo *resultRelInfo, + TupleTableSlot *slot, + EState *estate, + List *all_virtual_nns); extern bool ExecPartitionCheck(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate, bool emitError); extern void ExecPartitionCheckEmitError(ResultRelInfo *resultRelInfo, diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index af8f8a1e999..6159b8a3c07 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -551,6 +551,7 @@ typedef struct ResultRelInfo /* array of virtual generated not null constraint-checking expr states */ ExprState **ri_GeneratedNotNullExprs; + /* * Arrays of stored generated columns ExprStates for INSERT/UPDATE/MERGE. */ -- 2.39.5