Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite4942f7

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

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

‎src/backend/executor/nodeModifyTable.c

Lines changed: 1 addition & 1 deletion
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

Lines changed: 16 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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 insertconflicttestvalues(0,'Crowberry')on conflict (key, fruit) do nothing;
2121
explain (costs off)insert into insertconflicttestvalues(0,'Crowberry')on conflict (fruit, key, fruit, key) do nothing;
2222
explain (costs off)insert into insertconflicttestvalues(0,'Crowberry')on conflict (lower(fruit), key,lower(fruit), key) do nothing;
23+
explain (costs off)insert into insertconflicttestvalues(0,'Crowberry')on conflict (key, fruit) doupdateset fruit=excluded.fruit
24+
where exists (select1from insertconflicttest iiwhereii.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)

[8]ページ先頭

©2009-2025 Movatter.jp