Don't throw serialization errors for self-conflicts in INSERT ON CONFLICT.

Enterprise / PostgreSQL - Tom Lane [sss.pgh.pa.us] - 23 October 2016 17:36 UTC

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: Related-Discussion:

a6c0a5b Don't throw serialization errors for self-conflicts in INSERT ON CONFLICT.
src/backend/executor/nodeModifyTable.c | 13 ++-
.../expected/insert-conflict-do-nothing-2.out | 105 ++++++++++++++++++++
src/test/isolation/isolation_schedule | 1 +
.../specs/insert-conflict-do-nothing-2.spec | 34 +++++++
src/test/regress/expected/insert_conflict.out | 35 +++++++
src/test/regress/sql/insert_conflict.sql | 32 ++++++
6 files changed, 218 insertions(+), 2 deletions(-)

Upstream: git.postgresql.org


  • Share