Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d563931

Browse files
jianhe-funCommitfest Bot
authored and
Commitfest Bot
committed
soft error variant of ExecPrepareExpr, ExecInitExpr
Introduce function ExecPrepareExprSafe and ExecInitExprSafe. ExecPrepareExprSafe initialize for expression execution with soft error support. not all expression node support it. some like CoerceToDomain do support it. discussion: https://postgr.es/m/CACJufxFNUHxuSE=g20C2aLO3d+4T_j9h0x8esMirzcC4FrLbBg@mail.gmail.com
1 parent 7c4ccb0 commit d563931

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/backend/executor/execExpr.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,46 @@ ExecInitExpr(Expr *node, PlanState *parent)
170170
return state;
171171
}
172172

173+
/*
174+
* ExecInitExpr: soft error variant of ExecInitExpr.
175+
* use it only for expression nodes support soft errors, not all expression
176+
* nodes support it.
177+
*/
178+
ExprState *
179+
ExecInitExprSafe(Expr *node, PlanState *parent)
180+
{
181+
ExprState *state;
182+
ExprEvalStep scratch = {0};
183+
184+
/* Special case: NULL expression produces a NULL ExprState pointer */
185+
if (node == NULL)
186+
return NULL;
187+
188+
/* Initialize ExprState with empty step list */
189+
state = makeNode(ExprState);
190+
state->expr = node;
191+
state->parent = parent;
192+
state->ext_params = NULL;
193+
state->escontext = makeNode(ErrorSaveContext);
194+
state->escontext->type = T_ErrorSaveContext;
195+
state->escontext->error_occurred = false;
196+
state->escontext->details_wanted = true;
197+
198+
/* Insert setup steps as needed */
199+
ExecCreateExprSetupSteps(state, (Node *) node);
200+
201+
/* Compile the expression proper */
202+
ExecInitExprRec(node, state, &state->resvalue, &state->resnull);
203+
204+
/* Finally, append a DONE step */
205+
scratch.opcode = EEOP_DONE_RETURN;
206+
ExprEvalPushStep(state, &scratch);
207+
208+
ExecReadyExpr(state);
209+
210+
return state;
211+
}
212+
173213
/*
174214
* ExecInitExprWithParams: prepare a standalone expression tree for execution
175215
*
@@ -778,6 +818,29 @@ ExecPrepareExpr(Expr *node, EState *estate)
778818
return result;
779819
}
780820

821+
/*
822+
* ExecPrepareExprSafe: soft error variant of ExecPrepareExpr.
823+
*
824+
* use it when expression node *support* soft error expression execution.
825+
* ExecPrepareExpr comments apply to here too.
826+
*/
827+
ExprState *
828+
ExecPrepareExprSafe(Expr *node, EState *estate)
829+
{
830+
ExprState *result;
831+
MemoryContext oldcontext;
832+
833+
oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
834+
835+
node = expression_planner(node);
836+
837+
result = ExecInitExprSafe(node, NULL);
838+
839+
MemoryContextSwitchTo(oldcontext);
840+
841+
return result;
842+
}
843+
781844
/*
782845
* ExecPrepareQual --- initialize for qual execution outside a normal
783846
* Plan tree context.

src/include/executor/executor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ ExecProcNode(PlanState *node)
318318
* prototypes from functions in execExpr.c
319319
*/
320320
extern ExprState *ExecInitExpr(Expr *node, PlanState *parent);
321+
extern ExprState *ExecInitExprSafe(Expr *node, PlanState *parent);
321322
extern ExprState *ExecInitExprWithParams(Expr *node, ParamListInfo ext_params);
322323
extern ExprState *ExecInitQual(List *qual, PlanState *parent);
323324
extern ExprState *ExecInitCheck(List *qual, PlanState *parent);
@@ -366,6 +367,7 @@ extern ProjectionInfo *ExecBuildUpdateProjection(List *targetList,
366367
TupleTableSlot *slot,
367368
PlanState *parent);
368369
extern ExprState *ExecPrepareExpr(Expr *node, EState *estate);
370+
extern ExprState *ExecPrepareExprSafe(Expr *node, EState *estate);
369371
extern ExprState *ExecPrepareQual(List *qual, EState *estate);
370372
extern ExprState *ExecPrepareCheck(List *qual, EState *estate);
371373
extern List *ExecPrepareExprList(List *nodes, EState *estate);

0 commit comments

Comments
 (0)