Skip to content

Commit 1405e92

Browse files
author
Maksim Milyutin
committed
Refine compat version of ExecEvalExpr routine
1 parent 10838a1 commit 1405e92

File tree

4 files changed

+16
-31
lines changed

4 files changed

+16
-31
lines changed

src/include/compat/pg_compat.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,20 @@ extern void create_plain_partial_paths(PlannerInfo *root,
165165

166166
/*
167167
* ExecEvalExpr
168+
*
169+
* 'errmsg' specifies error string when result of ExecEvalExpr doesn't return
170+
* a single value
168171
*/
169172
#if PG_VERSION_NUM >= 100000
170-
#define ExecEvalExprCompat(expr, econtext, isNull, isDone) \
173+
#define ExecEvalExprCompat(expr, econtext, isNull, errmsg) \
171174
ExecEvalExpr((expr), (econtext), (isNull))
172-
#else
173-
#define ExecEvalExprCompat(expr, econtext, isNull, isDone) \
174-
ExecEvalExpr((expr), (econtext), (isNull), (isDone))
175+
#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)
175182
#endif
176183

177184

src/partition_filter.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,6 @@ partition_filter_exec(CustomScanState *node)
600600
ResultRelInfoHolder *rri_holder;
601601
bool isnull;
602602
Datum value;
603-
#if PG_VERSION_NUM < 100000
604-
ExprDoneCond itemIsDone;
605-
#endif
606603
TupleTableSlot *tmp_slot;
607604

608605
/* Fetch PartRelationInfo for this partitioned relation */
@@ -624,17 +621,12 @@ partition_filter_exec(CustomScanState *node)
624621
tmp_slot = econtext->ecxt_scantuple;
625622
econtext->ecxt_scantuple = slot;
626623
value = ExecEvalExprCompat(state->expr_state, econtext, &isnull,
627-
&itemIsDone);
624+
ERR_PART_ATTR_MULTIPLE_RESULTS);
628625
econtext->ecxt_scantuple = tmp_slot;
629626

630627
if (isnull)
631628
elog(ERROR, ERR_PART_ATTR_NULL);
632629

633-
#if PG_VERSION_NUM < 100000
634-
if (itemIsDone != ExprSingleResult)
635-
elog(ERROR, ERR_PART_ATTR_MULTIPLE_RESULTS);
636-
#endif
637-
638630
/* Search for a matching partition */
639631
rri_holder = select_partition_for_insert(value, prel->ev_type, prel,
640632
&state->result_parts, estate);

src/pl_funcs.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,9 +1153,6 @@ pathman_update_trigger_func(PG_FUNCTION_ARGS)
11531153
Datum value;
11541154
Oid value_type;
11551155
bool isnull;
1156-
#if PG_VERSION_NUM < 100000
1157-
ExprDoneCond itemIsDone;
1158-
#endif
11591156

11601157
Oid *parts;
11611158
int nparts;
@@ -1204,17 +1201,13 @@ pathman_update_trigger_func(PG_FUNCTION_ARGS)
12041201
source_rel,
12051202
new_tuple,
12061203
&value_type);
1207-
value = ExecEvalExprCompat(expr_state, econtext, &isnull, &itemIsDone);
1204+
value = ExecEvalExprCompat(expr_state, econtext, &isnull,
1205+
ERR_PART_ATTR_MULTIPLE_RESULTS);
12081206
MemoryContextSwitchTo(old_mcxt);
12091207

12101208
if (isnull)
12111209
elog(ERROR, ERR_PART_ATTR_NULL);
12121210

1213-
#if PG_VERSION_NUM < 100000
1214-
if (itemIsDone != ExprSingleResult)
1215-
elog(ERROR, ERR_PART_ATTR_MULTIPLE_RESULTS);
1216-
#endif
1217-
12181211
/* Search for matching partitions */
12191212
parts = find_partitions_for_value(value, value_type, prel, &nparts);
12201213

src/utility_stmt_hooking.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,6 @@ PathmanCopyFrom(CopyState cstate, Relation parent_rel,
607607
{
608608
TupleTableSlot *slot,
609609
*tmp_slot;
610-
#if PG_VERSION_NUM < 100000
611-
ExprDoneCond itemIsDone;
612-
#endif
613610
bool skip_tuple,
614611
isnull;
615612
Oid tuple_oid = InvalidOid;
@@ -653,17 +650,13 @@ PathmanCopyFrom(CopyState cstate, Relation parent_rel,
653650
/* Execute expression */
654651
tmp_slot = econtext->ecxt_scantuple;
655652
econtext->ecxt_scantuple = slot;
656-
value = ExecEvalExprCompat(expr_state, econtext, &isnull, &itemIsDone);
653+
value = ExecEvalExprCompat(expr_state, econtext, &isnull,
654+
ERR_PART_ATTR_MULTIPLE_RESULTS);
657655
econtext->ecxt_scantuple = tmp_slot;
658656

659657
if (isnull)
660658
elog(ERROR, ERR_PART_ATTR_NULL);
661659

662-
#if PG_VERSION_NUM < 100000
663-
if (itemIsDone != ExprSingleResult)
664-
elog(ERROR, ERR_PART_ATTR_MULTIPLE_RESULTS);
665-
#endif
666-
667660
/* Search for a matching partition */
668661
rri_holder = select_partition_for_insert(value,
669662
prel->ev_type, prel,

0 commit comments

Comments
 (0)