@@ -170,6 +170,46 @@ ExecInitExpr(Expr *node, PlanState *parent)
170
170
return state ;
171
171
}
172
172
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
+
173
213
/*
174
214
* ExecInitExprWithParams: prepare a standalone expression tree for execution
175
215
*
@@ -778,6 +818,29 @@ ExecPrepareExpr(Expr *node, EState *estate)
778
818
return result ;
779
819
}
780
820
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
+
781
844
/*
782
845
* ExecPrepareQual --- initialize for qual execution outside a normal
783
846
* Plan tree context.
0 commit comments