From: Dean Rasheed Date: Thu, 12 Feb 2026 09:01:42 +0000 (+0000) Subject: Remove p_is_insert from struct ParseState. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=706cadde3239842a41a3375d50dda8b33325c008;p=thirdparty%2Fpostgresql.git Remove p_is_insert from struct ParseState. The only place that used p_is_insert was transformAssignedExpr(), which used it to distinguish INSERT from UPDATE when handling indirection on assignment target columns -- see commit c1ca3a19df3. However, this information is already available to transformAssignedExpr() via its exprKind parameter, which is always either EXPR_KIND_INSERT_TARGET or EXPR_KIND_UPDATE_TARGET. As noted in the commit message for c1ca3a19df3, this use of p_is_insert isn't particularly pretty, so have transformAssignedExpr() use the exprKind parameter instead. This then allows p_is_insert to be removed entirely, which simplifies state management in a few other places across the parser. Author: Viktor Holmberg Reviewed-by: Dean Rasheed Discussion: https://postgr.es/m/badc3b4c-da73-4000-b8d3-638a6f53a769@Spark --- diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 029ca3b68c3..50d51c880d6 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -657,7 +657,6 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt) Assert(pstate->p_ctenamespace == NIL); qry->commandType = CMD_INSERT; - pstate->p_is_insert = true; /* process the WITH clause independently of all else */ if (stmt->withClause) @@ -1222,13 +1221,6 @@ transformOnConflictClause(ParseState *pstate, /* Process DO UPDATE */ if (onConflictClause->action == ONCONFLICT_UPDATE) { - /* - * Expressions in the UPDATE targetlist need to be handled like UPDATE - * not INSERT. We don't need to save/restore this because all INSERT - * expressions have been parsed already. - */ - pstate->p_is_insert = false; - /* * Add the EXCLUDED pseudo relation to the query namespace, making it * available in the UPDATE subexpressions. @@ -2495,7 +2487,6 @@ transformUpdateStmt(ParseState *pstate, UpdateStmt *stmt) Node *qual; qry->commandType = CMD_UPDATE; - pstate->p_is_insert = false; /* process the WITH clause independently of all else */ if (stmt->withClause) diff --git a/src/backend/parser/parse_merge.c b/src/backend/parser/parse_merge.c index e08dc18dd75..0a70d48fd4c 100644 --- a/src/backend/parser/parse_merge.c +++ b/src/backend/parser/parse_merge.c @@ -307,8 +307,6 @@ transformMergeStmt(ParseState *pstate, MergeStmt *stmt) List *icolumns; List *attrnos; - pstate->p_is_insert = true; - icolumns = checkInsertTargets(pstate, mergeWhenClause->targetList, &attrnos); @@ -381,12 +379,9 @@ transformMergeStmt(ParseState *pstate, MergeStmt *stmt) } break; case CMD_UPDATE: - { - pstate->p_is_insert = false; - action->targetList = - transformUpdateTargetList(pstate, - mergeWhenClause->targetList); - } + action->targetList = + transformUpdateTargetList(pstate, + mergeWhenClause->targetList); break; case CMD_DELETE: break; diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c index b5a2f915b67..dbf5b2b5c01 100644 --- a/src/backend/parser/parse_target.c +++ b/src/backend/parser/parse_target.c @@ -438,6 +438,7 @@ markTargetListOrigin(ParseState *pstate, TargetEntry *tle, * pstate parse state * expr expression to be modified * exprKind indicates which type of statement we're dealing with + * (EXPR_KIND_INSERT_TARGET or EXPR_KIND_UPDATE_TARGET) * colname target column name (ie, name of attribute to be assigned to) * attrno target attribute number * indirection subscripts/field names for target column, if any @@ -471,7 +472,8 @@ transformAssignedExpr(ParseState *pstate, * set p_expr_kind here because we can parse subscripts without going * through transformExpr(). */ - Assert(exprKind != EXPR_KIND_NONE); + Assert(exprKind == EXPR_KIND_INSERT_TARGET || + exprKind == EXPR_KIND_UPDATE_TARGET); sv_expr_kind = pstate->p_expr_kind; pstate->p_expr_kind = exprKind; @@ -530,7 +532,7 @@ transformAssignedExpr(ParseState *pstate, { Node *colVar; - if (pstate->p_is_insert) + if (exprKind == EXPR_KIND_INSERT_TARGET) { /* * The command is INSERT INTO table (col.something) ... so there diff --git a/src/include/parser/parse_node.h b/src/include/parser/parse_node.h index a9bffb8a78f..f23e21f318b 100644 --- a/src/include/parser/parse_node.h +++ b/src/include/parser/parse_node.h @@ -153,10 +153,6 @@ typedef Node *(*CoerceParamHook) (ParseState *pstate, Param *param, * * p_grouping_nsitem: the ParseNamespaceItem that represents the grouping step. * - * p_is_insert: true to process assignment expressions like INSERT, false - * to process them like UPDATE. (Note this can change intra-statement, for - * cases like INSERT ON CONFLICT UPDATE.) - * * p_windowdefs: list of WindowDefs representing WINDOW and OVER clauses. * We collect these while transforming expressions and then transform them * afterwards (so that any resjunk tlist items needed for the sort/group @@ -209,7 +205,6 @@ struct ParseState Relation p_target_relation; /* INSERT/UPDATE/DELETE/MERGE target rel */ ParseNamespaceItem *p_target_nsitem; /* target rel's NSItem, or NULL */ ParseNamespaceItem *p_grouping_nsitem; /* NSItem for grouping, or NULL */ - bool p_is_insert; /* process assignment like INSERT not UPDATE */ List *p_windowdefs; /* raw representations of window clauses */ ParseExprKind p_expr_kind; /* what kind of expression we're parsing */ int p_next_resno; /* next targetlist resno to assign */