Re: BUG #12330: ACID is broken for unique constraints

From: Peter Geoghegan <pg(at)heroku(dot)com>
To: Kevin Grittner <kgrittn(at)ymail(dot)com>
Cc: "nikita(dot)y(dot)volkov(at)mail(dot)ru" <nikita(dot)y(dot)volkov(at)mail(dot)ru>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: BUG #12330: ACID is broken for unique constraints
Date: 2014-12-26 20:05:16
Message-ID: CAM3SWZTosvXwTZ8oZBzi2SfJ4F+YZASGNLyc8mzy=73ccGtikQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

On Fri, Dec 26, 2014 at 7:23 AM, Kevin Grittner <kgrittn(at)ymail(dot)com> wrote:
> Are there any objections to generating a write conflict instead of
> a duplicate key error if the duplicate key was added by a
> concurrent transaction? Only for transactions at isolation level
> REPEATABLE READ or higher?

This independently occurred to me as perhaps preferable over a year
ago. The INSERT...ON CONFLICT IGNORE feature that my patch adds will
throw such an error for REPEATABLE READ and higher modes rather than
proceeding on the basis of having ignored something from a concurrent
transaction.

+1 from me for doing this in the master branch, if it isn't too
invasive (I think it might be; where is estate available from to work
with close to duplicate checking for B-Trees?). It only makes sense to
do what you propose if the users expects to check that there is no
duplicate ahead of time, and only ever fail with a serialization
failure (not a duplicate violation) from concurrent conflicts. That is
a bit narrow; the OP can only reasonably expect to not see a duplicate
violation on retry because he happens to be checking...most clients
won't, and will "waste" a retry.

The proposed ON CONFLICT IGNORE feature would do this checking for him
correctly, FWIW, but in typical cases there is no real point in
retrying the xact -- you'll just get another duplicate violation
error.

In any case I think exclusion violations should be covered, too.
--
Peter Geoghegan

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Merlin Moncure 2014-12-27 05:56:18 Re: BUG #12330: ACID is broken for unique constraints
Previous Message Nikita Volkov 2014-12-26 18:45:32 Re: BUG #12330: ACID is broken for unique constraints

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2014-12-26 21:56:36 Re: Better way of dealing with pgstat wait timeout during buildfarm runs?
Previous Message Abhijit Menon-Sen 2014-12-26 18:50:23 Re: What exactly is our CRC algorithm?