Skip to content

Commit 9f92153

Browse files
author
Maksim Milyutin
committed
Fix ExecEvalExpr wrapper macro and add compat versions of initial_cost_nextloop and create_nestloop_path routines
1 parent 1405e92 commit 9f92153

File tree

6 files changed

+73
-40
lines changed

6 files changed

+73
-40
lines changed

src/compat/pg_compat.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,17 @@ create_plain_partial_paths(PlannerInfo *root, RelOptInfo *rel)
202202
#endif
203203

204204

205+
/*
206+
* ExecEvalExpr
207+
*
208+
* global variables for macro wrapper evaluation
209+
*/
210+
#if PG_VERSION_NUM >= 90500 && PG_VERSION_NUM < 100000
211+
Datum exprResult;
212+
ExprDoneCond isDone;
213+
#endif
214+
215+
205216
/*
206217
* make_result
207218
* Build a Result plan node

src/hooks.c

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,8 @@ pathman_join_pathlist_hook(PlannerInfo *root,
217217
have_dangerous_phv(root, outer->parent->relids, required_inner)))
218218
return;
219219

220-
221-
/* TODO: create macro initial_cost_nestloop_compat() */
222-
#if (defined(PGPRO_VERSION) && PG_VERSION_NUM >= 90603) || \
223-
PG_VERSION_NUM >= 100000
224-
initial_cost_nestloop(root, &workspace, jointype,
225-
outer, inner, /* built paths */
226-
extra);
227-
#else
228-
initial_cost_nestloop(root, &workspace, jointype,
229-
outer, inner, /* built paths */
230-
extra->sjinfo, &extra->semifactors);
231-
#endif
220+
initial_cost_nestloop_compat(root, &workspace, jointype, outer, inner,
221+
extra);
232222

233223
pathkeys = build_join_pathkeys(root, joinrel, jointype, outer->pathkeys);
234224

@@ -242,24 +232,11 @@ pathman_join_pathlist_hook(PlannerInfo *root,
242232
filtered_joinclauses = lappend(filtered_joinclauses, rinfo);
243233
}
244234

245-
/* TODO: create macro create_nestloop_path_compat() */
246-
#if (defined(PGPRO_VERSION) && PG_VERSION_NUM >= 90603) || \
247-
PG_VERSION_NUM >= 100000
248-
nest_path = create_nestloop_path(root, joinrel, jointype, &workspace,
249-
extra,
250-
outer, inner,
251-
filtered_joinclauses,
252-
pathkeys,
253-
calc_nestloop_required_outer(outer, inner));
254-
#else
255-
nest_path = create_nestloop_path(root, joinrel, jointype, &workspace,
256-
extra->sjinfo,
257-
&extra->semifactors,
258-
outer, inner,
259-
filtered_joinclauses,
260-
pathkeys,
261-
calc_nestloop_required_outer(outer, inner));
262-
#endif
235+
nest_path =
236+
create_nestloop_path_compat(root, joinrel, jointype,
237+
&workspace, extra, outer, inner,
238+
filtered_joinclauses, pathkeys,
239+
calc_nestloop_required_outer(outer, inner));
263240

264241
/*
265242
* NOTE: Override 'rows' value produced by standard estimator.

src/include/compat/pg_compat.h

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,27 @@ void CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple);
137137
#endif /* PG_VERSION_NUM */
138138

139139

140+
/*
141+
* create_nestloop_path()
142+
*/
143+
#if PG_VERSION_NUM >= 100000
144+
#define create_nestloop_path_compat(root, joinrel, jointype, workspace, extra, \
145+
outer, inner, filtered_joinclauses, pathkeys, \
146+
required_outer) \
147+
create_nestloop_path((root), (joinrel), (jointype), (workspace), (extra), \
148+
(outer), (inner), (filtered_joinclauses), (pathkeys), \
149+
(required_outer))
150+
#elif PG_VERSION_NUM >= 90500
151+
#define create_nestloop_path_compat(root, joinrel, jointype, workspace, extra, \
152+
outer, inner, filtered_joinclauses, pathkeys, \
153+
required_outer) \
154+
create_nestloop_path((root), (joinrel), (jointype), (workspace), \
155+
(extra)->sjinfo, &(extra)->semifactors, (outer), \
156+
(inner), (filtered_joinclauses), (pathkeys), \
157+
(required_outer))
158+
#endif
159+
160+
140161
/*
141162
* create_plain_partial_paths()
142163
*/
@@ -170,15 +191,23 @@ extern void create_plain_partial_paths(PlannerInfo *root,
170191
* a single value
171192
*/
172193
#if PG_VERSION_NUM >= 100000
173-
#define ExecEvalExprCompat(expr, econtext, isNull, errmsg) \
194+
#define ExecEvalExprCompat(expr, econtext, isNull, errHandler) \
174195
ExecEvalExpr((expr), (econtext), (isNull))
175196
#elif PG_VERSION_NUM >= 90500
176-
#define ExecEvalExprCompat(expr, econtext, isNull, errmsg) \
177-
do { \
178-
ExecEvalExpr((expr), (econtext), (isNull), (isDone)); \
179-
if (isDone != ExprSingleResult) \
180-
elog(ERROR, (errmsg)); \
181-
} while (0)
197+
#include "partition_filter.h"
198+
extern Datum exprResult;
199+
extern ExprDoneCond isDone;
200+
static inline void
201+
not_signle_result_handler()
202+
{
203+
elog(ERROR, ERR_PART_ATTR_MULTIPLE_RESULTS);
204+
}
205+
#define ExecEvalExprCompat(expr, econtext, isNull, errHandler) \
206+
( \
207+
exprResult = ExecEvalExpr((expr), (econtext), (isNull), &isDone), \
208+
(isDone != ExprSingleResult) ? (errHandler)() : (0), \
209+
exprResult \
210+
)
182211
#endif
183212

184213

@@ -212,6 +241,22 @@ char get_rel_persistence(Oid relid);
212241
#endif
213242

214243

244+
/*
245+
* initial_cost_nestloop
246+
*/
247+
#if PG_VERSION_NUM >= 100000 || (defined(PGPRO_VERSION) && PG_VERSION_NUM >= 90603)
248+
#define initial_cost_nestloop_compat(root, workspace, jointype, outer_path, \
249+
inner_path, extra) \
250+
initial_cost_nestloop((root), (workspace), (jointype), (outer_path), \
251+
(inner_path), (extra))
252+
#elif PG_VERSION_NUM >= 90500
253+
#define initial_cost_nestloop_compat(root, workspace, jointype, outer_path, \
254+
inner_path, extra) \
255+
initial_cost_nestloop((root), (workspace), (jointype), (outer_path), \
256+
(inner_path), (extra)->sjinfo, &(extra)->semifactors)
257+
#endif
258+
259+
215260
/*
216261
* InitResultRelInfo
217262
*

src/partition_filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ partition_filter_exec(CustomScanState *node)
621621
tmp_slot = econtext->ecxt_scantuple;
622622
econtext->ecxt_scantuple = slot;
623623
value = ExecEvalExprCompat(state->expr_state, econtext, &isnull,
624-
ERR_PART_ATTR_MULTIPLE_RESULTS);
624+
not_signle_result_handler);
625625
econtext->ecxt_scantuple = tmp_slot;
626626

627627
if (isnull)

src/pl_funcs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ pathman_update_trigger_func(PG_FUNCTION_ARGS)
12021202
new_tuple,
12031203
&value_type);
12041204
value = ExecEvalExprCompat(expr_state, econtext, &isnull,
1205-
ERR_PART_ATTR_MULTIPLE_RESULTS);
1205+
not_signle_result_handler);
12061206
MemoryContextSwitchTo(old_mcxt);
12071207

12081208
if (isnull)

src/utility_stmt_hooking.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ PathmanCopyFrom(CopyState cstate, Relation parent_rel,
651651
tmp_slot = econtext->ecxt_scantuple;
652652
econtext->ecxt_scantuple = slot;
653653
value = ExecEvalExprCompat(expr_state, econtext, &isnull,
654-
ERR_PART_ATTR_MULTIPLE_RESULTS);
654+
not_signle_result_handler);
655655
econtext->ecxt_scantuple = tmp_slot;
656656

657657
if (isnull)

0 commit comments

Comments
 (0)