]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Remove p_is_insert from struct ParseState.
authorDean Rasheed <dean.a.rasheed@gmail.com>
Thu, 12 Feb 2026 09:01:42 +0000 (09:01 +0000)
committerDean Rasheed <dean.a.rasheed@gmail.com>
Thu, 12 Feb 2026 09:01:42 +0000 (09:01 +0000)
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 <v@viktorh.net>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
Discussion: https://postgr.es/m/badc3b4c-da73-4000-b8d3-638a6f53a769@Spark

src/backend/parser/analyze.c
src/backend/parser/parse_merge.c
src/backend/parser/parse_target.c
src/include/parser/parse_node.h

index 029ca3b68c3214a3794a450cd6ee686e2110d0bd..50d51c880d6f6ae08cd6c0ade12ddb7b71f7d63f 100644 (file)
@@ -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)
index e08dc18dd75d9f8c7f6fa4d03c97748b76f8b5c4..0a70d48fd4cfcd54020ebdafd8a1e0ce4fb8121a 100644 (file)
@@ -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;
index b5a2f915b67814a71592cfc5c7b97aa39b442a30..dbf5b2b5c01ca5fa258f15a03215fbf36e36afa4 100644 (file)
@@ -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
index a9bffb8a78ff4a193cdba4528a3cd9ee605e910c..f23e21f318bfcce650beb2688062821b1dfe8247 100644 (file)
@@ -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 */