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 c1ca3a19df.
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 c1ca3a19df, 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
This commit is contained in:
Dean Rasheed 2026-02-12 09:01:42 +00:00
parent cf74558feb
commit 706cadde32
4 changed files with 7 additions and 24 deletions

View 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)

View 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;

View 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

View 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 */