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

Commit d143a11

Browse files
jianhe-funCommitfest Bot
authored and
Commitfest Bot
committed
soft error variant of ExecPrepareExpr, ExecInitExpr
ExecInitExprSafe: soft error of ExecInitExpr. ExecPrepareExprSafe: soft error of ExecPrepareExpr. ExecPrepareExprSafe initialize for expression execution with soft error support. not all expression node support it. Like node CoerceToDomain support it. XXX more comments. discussion: https://postgr.es/m/CACJufxE_+iZBR1i49k_AHigppPwLTJi6km8NOsC7FWvKdEmmXg@mail.gmail.com
1 parent 4c08ecd commit d143a11

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,47 @@ ExecInitExpr(Expr *node, PlanState *parent)
170170
return state;
171171
}
172172

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

822+
/*
823+
* ExecPrepareExprSafe: soft error variant of ExecPrepareExpr.
824+
*
825+
* use it when expression node *support* soft error expression execution.
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)