Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e4942f7

Browse files
committed
Attach ON CONFLICT SET ... WHERE to the correct planstate.
The previous coding was a leftover from attempting to hang all the on conflict logic onto modify table's child nodes. It appears to not have actually caused problems except for explain. Add test exercising the broken and some other code paths. Author: Peter Geoghegan and Andres Freund
1 parent 4db485e commit e4942f7

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/backend/executor/nodeModifyTable.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,7 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
16971697
ExprState *qualexpr;
16981698

16991699
qualexpr = ExecInitExpr((Expr *) node->onConflictWhere,
1700-
mtstate->mt_plans[0]);
1700+
&mtstate->ps);
17011701

17021702
resultRelInfo->ri_onConflictSetWhere = (List *) qualexpr;
17031703
}

src/test/regress/expected/insert_conflict.out

+16
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ explain (costs off) insert into insertconflicttest values(0, 'Crowberry') on con
4343
-> Result
4444
(4 rows)
4545

46+
explain (costs off) insert into insertconflicttest values(0, 'Crowberry') on conflict (key, fruit) do update set fruit = excluded.fruit
47+
where exists (select 1 from insertconflicttest ii where ii.key = excluded.key);
48+
QUERY PLAN
49+
-------------------------------------------------------------------------------
50+
Insert on insertconflicttest
51+
Conflict Resolution: UPDATE
52+
Conflict Arbiter Indexes: op_index_key, collation_index_key, both_index_key
53+
Conflict Filter: (alternatives: SubPlan 1 or hashed SubPlan 2)
54+
-> Result
55+
SubPlan 1
56+
-> Index Only Scan using both_index_expr_key on insertconflicttest ii
57+
Index Cond: (key = excluded.key)
58+
SubPlan 2
59+
-> Seq Scan on insertconflicttest ii_1
60+
(10 rows)
61+
4662
-- Neither collation nor operator class specifications are required --
4763
-- supplying them merely *limits* matches to indexes with matching opclasses
4864
-- used for relevant indexes

src/test/regress/sql/insert_conflict.sql

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ explain (costs off) insert into insertconflicttest values(0, 'Crowberry') on con
2020
explain (costs off) insert into insertconflicttest values(0, 'Crowberry') on conflict (key, fruit) do nothing;
2121
explain (costs off) insert into insertconflicttest values(0, 'Crowberry') on conflict (fruit, key, fruit, key) do nothing;
2222
explain (costs off) insert into insertconflicttest values(0, 'Crowberry') on conflict (lower(fruit), key, lower(fruit), key) do nothing;
23+
explain (costs off) insert into insertconflicttest values(0, 'Crowberry') on conflict (key, fruit) do update set fruit = excluded.fruit
24+
where exists (select 1 from insertconflicttest ii where ii.key = excluded.key);
2325
-- Neither collation nor operator class specifications are required --
2426
-- supplying them merely *limits* matches to indexes with matching opclasses
2527
-- used for relevant indexes

0 commit comments

Comments
 (0)