@@ -144,23 +144,22 @@ IsConstValue(Node *node, const WalkerContext *context)
144
144
static Const *
145
145
ExtractConst (Node * node , const WalkerContext * context )
146
146
{
147
- ExprState * estate ;
147
+ ExprState * estate ;
148
+ ExprContext * econtext = context -> econtext ;
148
149
149
- Datum value ;
150
- bool isnull ;
150
+ Datum value ;
151
+ bool isnull ;
151
152
152
- Oid typid ,
153
- collid ;
154
- int typmod ;
153
+ Oid typid ,
154
+ collid ;
155
+ int typmod ;
155
156
156
157
/* Fast path for Consts */
157
158
if (IsA (node , Const ))
158
159
return (Const * ) node ;
159
160
160
- /* Evaluate expression */
161
- estate = ExecInitExpr ((Expr * ) node , NULL );
162
- value = ExecEvalExprCompat (estate , context -> econtext , & isnull ,
163
- mult_result_handler );
161
+ /* Just a paranoid check */
162
+ Assert (IsConstValue (node , context ));
164
163
165
164
switch (nodeTag (node ))
166
165
{
@@ -171,6 +170,9 @@ ExtractConst(Node *node, const WalkerContext *context)
171
170
typid = param -> paramtype ;
172
171
typmod = param -> paramtypmod ;
173
172
collid = param -> paramcollid ;
173
+
174
+ /* It must be provided */
175
+ Assert (WcxtHasExprContext (context ));
174
176
}
175
177
break ;
176
178
@@ -179,15 +181,33 @@ ExtractConst(Node *node, const WalkerContext *context)
179
181
RowExpr * row = (RowExpr * ) node ;
180
182
181
183
typid = row -> row_typeid ;
182
- typmod = - 1 ;
184
+ typmod = -1 ;
183
185
collid = InvalidOid ;
186
+
187
+ #if PG_VERSION_NUM >= 100000
188
+ /* If there's no context - create it! */
189
+ if (!WcxtHasExprContext (context ))
190
+ econtext = CreateStandaloneExprContext ();
191
+ #endif
184
192
}
185
193
break ;
186
194
187
195
default :
188
- elog (ERROR , "error in function " CppAsString (ExtractConst ));;
196
+ elog (ERROR , "error in function " CppAsString (ExtractConst ));
189
197
}
190
198
199
+ /* Evaluate expression */
200
+ estate = ExecInitExpr ((Expr * ) node , NULL );
201
+ value = ExecEvalExprCompat (estate , econtext , & isnull ,
202
+ mult_result_handler );
203
+
204
+ #if PG_VERSION_NUM >= 100000
205
+ /* Free temp econtext if needed */
206
+ if (econtext && !WcxtHasExprContext (context ))
207
+ FreeExprContext (econtext , true);
208
+ #endif
209
+
210
+ /* Finally return Const */
191
211
return makeConst (typid , typmod , collid , get_typlen (typid ),
192
212
value , isnull , get_typbyval (typid ));
193
213
}
0 commit comments