Don't throw serialization errors for self-conflicts in INSERT ON CONFLICT.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 23 Oct 2016 22:36:13 +0000 (18:36 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 23 Oct 2016 22:36:13 +0000 (18:36 -0400)
commita6c0a5b6e8a9498540c6a7bb1b6d68958acc9bc6
tree641cf19d24b949fe0ab8dea0cff3ea50b0ad4714
parent6292c2339186bac215bab5a1f01370f9735582c1
Don't throw serialization errors for self-conflicts in INSERT ON CONFLICT.

A transaction that conflicts against itself, for example
INSERT INTO t(pk) VALUES (1),(1) ON CONFLICT DO NOTHING;
should behave the same regardless of isolation level.  It certainly
shouldn't throw a serialization error, as retrying will not help.
We got this wrong due to the ON CONFLICT logic not considering the case,
as reported by Jason Dusek.

Core of this patch is by Peter Geoghegan (based on an earlier patch by
Thomas Munro), though I didn't take his proposed code refactoring for fear
that it might have unexpected side-effects.  Test cases by Thomas Munro
and myself.

Report: <CAO3NbwOycQjt2Oqy2VW-eLTq2M5uGMyHnGm=RNga4mjqcYD7gQ@mail.gmail.com>
Related-Discussion: <57EE93C8.8080504@postgrespro.ru>
src/backend/executor/nodeModifyTable.c
src/test/isolation/expected/insert-conflict-do-nothing-2.out [new file with mode: 0644]
src/test/isolation/isolation_schedule
src/test/isolation/specs/insert-conflict-do-nothing-2.spec [new file with mode: 0644]
src/test/regress/expected/insert_conflict.out
src/test/regress/sql/insert_conflict.sql