From 4af6e61a363246cf7fff3368a76603b0ce9945dd Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Wed, 13 May 2015 00:13:22 +0200 Subject: Fix ON CONFLICT bugs that manifest when used in rules. Specifically the tlist and rti of the pseudo "excluded" relation weren't properly treated by expression_tree_walker, which lead to errors when excluded was referenced inside a rule because the varnos where not properly adjusted. Similar omissions in OffsetVarNodes and expression_tree_mutator had less impact, but should obviously be fixed nonetheless. A couple tests of for ON CONFLICT UPDATE into INSERT rule bearing relations have been added. In passing I updated a couple comments. --- src/backend/optimizer/plan/setrefs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/backend/optimizer/plan/setrefs.c') diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c index fac51c91474..517409d28a0 100644 --- a/src/backend/optimizer/plan/setrefs.c +++ b/src/backend/optimizer/plan/setrefs.c @@ -740,9 +740,9 @@ set_plan_refs(PlannerInfo *root, Plan *plan, int rtoffset) /* * We treat ModifyTable with ON CONFLICT as a form of 'pseudo - * join', where the inner side is the EXLUDED tuple. Therefore - * use fix_join_expr to setup the relevant variables to - * INNER_VAR. We explicitly don't create any OUTER_VARs as + * join', where the inner side is the EXCLUDED tuple. + * Therefore use fix_join_expr to setup the relevant variables + * to INNER_VAR. We explicitly don't create any OUTER_VARs as * those are already used by RETURNING and it seems better to * be non-conflicting. */ @@ -763,6 +763,9 @@ set_plan_refs(PlannerInfo *root, Plan *plan, int rtoffset) NULL, itlist, linitial_int(splan->resultRelations), rtoffset); + + splan->exclRelTlist = + fix_scan_list(root, splan->exclRelTlist, rtoffset); } splan->nominalRelation += rtoffset; -- cgit v1.2.3