From a59a35be8308c6e48c4b07d5ccd835a2245224f0 Mon Sep 17 00:00:00 2001 From: shihao zhong Date: Mon, 2 Nov 2026 23:58:10 -0500 Subject: [PATCH v1 2/2] Group generated column fields in ResultRelInfo Keep the valid flags next to the fields they describe. Master only, since this changes the struct layout. Suggested-by: Tom Lane Discussion: https://postgr.es/m/ddc34dbd-1efc-4710-824c-e101e7eb63e6@postgrespro.ru --- src/backend/executor/execMain.c | 2 +- src/include/nodes/execnodes.h | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index d453589cb5d..4da52f7dbbf 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -1324,7 +1324,6 @@ InitResultRelInfo(ResultRelInfo *resultRelInfo, /* The following fields are set later if needed */ resultRelInfo->ri_RowIdAttNo = 0; - resultRelInfo->ri_extraUpdatedCols = NULL; resultRelInfo->ri_projectNew = NULL; resultRelInfo->ri_newTupleSlot = NULL; resultRelInfo->ri_oldTupleSlot = NULL; @@ -1337,6 +1336,7 @@ InitResultRelInfo(ResultRelInfo *resultRelInfo, resultRelInfo->ri_GeneratedExprsU = NULL; resultRelInfo->ri_GeneratedExprsI_valid = false; resultRelInfo->ri_GeneratedExprsU_valid = false; + resultRelInfo->ri_extraUpdatedCols = NULL; resultRelInfo->ri_projectReturning = NULL; resultRelInfo->ri_onConflictArbiterIndexes = NIL; resultRelInfo->ri_onConflict = NULL; diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index 7ddcd9e116f..9e9f2c81b54 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -508,11 +508,6 @@ typedef struct ResultRelInfo */ AttrNumber ri_RowIdAttNo; - /* For UPDATE, attnums of generated columns to be computed */ - Bitmapset *ri_extraUpdatedCols; - /* true if the above has been computed */ - bool ri_extraUpdatedCols_valid; - /* Projection to generate new tuple in an INSERT/UPDATE */ ProjectionInfo *ri_projectNew; /* Slot to hold that tuple */ @@ -575,18 +570,23 @@ typedef struct ResultRelInfo ExprState **ri_GenVirtualNotNullConstraintExprs; /* - * Arrays of stored generated columns ExprStates for INSERT/UPDATE/MERGE. + * Generated column setup, done by ExecInitGenerated() on first use, + * separately for INSERT and for UPDATE. A NULL array is a valid result, + * so each group has its own flag to show whether it has been computed. */ + /* arrays of ExprStates for stored generated columns */ ExprState **ri_GeneratedExprsI; ExprState **ri_GeneratedExprsU; - /* number of stored generated columns we need to compute */ int ri_NumGeneratedNeededI; int ri_NumGeneratedNeededU; - - /* true if the above INSERT, respectively UPDATE, fields are computed */ + /* true if the INSERT, respectively UPDATE, fields above are computed */ bool ri_GeneratedExprsI_valid; bool ri_GeneratedExprsU_valid; + /* for UPDATE, true if ri_extraUpdatedCols has been computed */ + bool ri_extraUpdatedCols_valid; + /* for UPDATE, attnums of stored and virtual generated columns */ + Bitmapset *ri_extraUpdatedCols; /* list of RETURNING expressions */ List *ri_returningList; -- 2.37.1 (Apple Git-137.1)