Skip to content

Commit 3a05cfa

Browse files
committed
fix ExtractConst() for PostgreSQL 10
1 parent 4c166c1 commit 3a05cfa

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

src/pg_pathman.c

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,22 @@ IsConstValue(Node *node, const WalkerContext *context)
144144
static Const *
145145
ExtractConst(Node *node, const WalkerContext *context)
146146
{
147-
ExprState *estate;
147+
ExprState *estate;
148+
ExprContext *econtext = context->econtext;
148149

149-
Datum value;
150-
bool isnull;
150+
Datum value;
151+
bool isnull;
151152

152-
Oid typid,
153-
collid;
154-
int typmod;
153+
Oid typid,
154+
collid;
155+
int typmod;
155156

156157
/* Fast path for Consts */
157158
if (IsA(node, Const))
158159
return (Const *) node;
159160

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));
164163

165164
switch (nodeTag(node))
166165
{
@@ -171,6 +170,9 @@ ExtractConst(Node *node, const WalkerContext *context)
171170
typid = param->paramtype;
172171
typmod = param->paramtypmod;
173172
collid = param->paramcollid;
173+
174+
/* It must be provided */
175+
Assert(WcxtHasExprContext(context));
174176
}
175177
break;
176178

@@ -179,15 +181,33 @@ ExtractConst(Node *node, const WalkerContext *context)
179181
RowExpr *row = (RowExpr *) node;
180182

181183
typid = row->row_typeid;
182-
typmod = - 1;
184+
typmod = -1;
183185
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
184192
}
185193
break;
186194

187195
default:
188-
elog(ERROR, "error in function " CppAsString(ExtractConst));;
196+
elog(ERROR, "error in function " CppAsString(ExtractConst));
189197
}
190198

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 */
191211
return makeConst(typid, typmod, collid, get_typlen(typid),
192212
value, isnull, get_typbyval(typid));
193213
}

0 commit comments

Comments
 (0)