提交 e4942f7a 编写于 作者: A Andres Freund

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
上级 4db485e7
...@@ -1697,7 +1697,7 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags) ...@@ -1697,7 +1697,7 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
ExprState *qualexpr; ExprState *qualexpr;
qualexpr = ExecInitExpr((Expr *) node->onConflictWhere, qualexpr = ExecInitExpr((Expr *) node->onConflictWhere,
mtstate->mt_plans[0]); &mtstate->ps);
resultRelInfo->ri_onConflictSetWhere = (List *) qualexpr; resultRelInfo->ri_onConflictSetWhere = (List *) qualexpr;
} }
......
...@@ -43,6 +43,22 @@ explain (costs off) insert into insertconflicttest values(0, 'Crowberry') on con ...@@ -43,6 +43,22 @@ explain (costs off) insert into insertconflicttest values(0, 'Crowberry') on con
-> Result -> Result
(4 rows) (4 rows)
explain (costs off) insert into insertconflicttest values(0, 'Crowberry') on conflict (key, fruit) do update set fruit = excluded.fruit
where exists (select 1 from insertconflicttest ii where ii.key = excluded.key);
QUERY PLAN
-------------------------------------------------------------------------------
Insert on insertconflicttest
Conflict Resolution: UPDATE
Conflict Arbiter Indexes: op_index_key, collation_index_key, both_index_key
Conflict Filter: (alternatives: SubPlan 1 or hashed SubPlan 2)
-> Result
SubPlan 1
-> Index Only Scan using both_index_expr_key on insertconflicttest ii
Index Cond: (key = excluded.key)
SubPlan 2
-> Seq Scan on insertconflicttest ii_1
(10 rows)
-- Neither collation nor operator class specifications are required -- -- Neither collation nor operator class specifications are required --
-- supplying them merely *limits* matches to indexes with matching opclasses -- supplying them merely *limits* matches to indexes with matching opclasses
-- used for relevant indexes -- used for relevant indexes
......
...@@ -20,6 +20,8 @@ explain (costs off) insert into insertconflicttest values(0, 'Crowberry') on con ...@@ -20,6 +20,8 @@ explain (costs off) insert into insertconflicttest values(0, 'Crowberry') on con
explain (costs off) insert into insertconflicttest values(0, 'Crowberry') on conflict (key, fruit) do nothing; explain (costs off) insert into insertconflicttest values(0, 'Crowberry') on conflict (key, fruit) do nothing;
explain (costs off) insert into insertconflicttest values(0, 'Crowberry') on conflict (fruit, key, fruit, key) do nothing; explain (costs off) insert into insertconflicttest values(0, 'Crowberry') on conflict (fruit, key, fruit, key) do nothing;
explain (costs off) insert into insertconflicttest values(0, 'Crowberry') on conflict (lower(fruit), key, lower(fruit), key) do nothing; explain (costs off) insert into insertconflicttest values(0, 'Crowberry') on conflict (lower(fruit), key, lower(fruit), key) do nothing;
explain (costs off) insert into insertconflicttest values(0, 'Crowberry') on conflict (key, fruit) do update set fruit = excluded.fruit
where exists (select 1 from insertconflicttest ii where ii.key = excluded.key);
-- Neither collation nor operator class specifications are required -- -- Neither collation nor operator class specifications are required --
-- supplying them merely *limits* matches to indexes with matching opclasses -- supplying them merely *limits* matches to indexes with matching opclasses
-- used for relevant indexes -- used for relevant indexes
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册