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

From: Greg Stark <stark(at)mit(dot)edu>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Kevin Grittner <kgrittn(at)ymail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Josh Berkus <josh(at)agliodbs(dot)com>, "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-30 17:24:18
Message-ID: CAM-w4HN62W7T=gij29g85Ei_5sCLrr1Cc9Ze_smte3xtf7Vv-w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

On Mon, Dec 29, 2014 at 4:17 PM, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
> Serialization errors only exist as a concession
> to concurrency and performance. Again, they should be returned as
> sparsely as possible

I think this is fuzzy thinking. Serialization *errors* themselves are
a concession to concurrency and performance but the actual signaling
of the errors is just a consequence that the serialization failure
occurred. If you can find a way to avoid the serialization failure
then yay but you can't just not report it and call that a win.

The point of returning a serialization failure is to report when a
transaction sees something that can't be possible in a serialized
execution. It's not that "retrying might make the error go away" it's
that the error shouldn't have been possible in a serialized execution
so the code shouldn't have to be prepared for it.

So if you get a unique violation or an RI violation and the
transaction didn't previously verify that the constraint wouldn't be
violated then it's perfectly ok to return a constraint violation
error. It doesn't matter whether retrying might avoid the error since
there was some serialized order in which the constraint was violated.

The case at issue is things like upsert where the code already
verified that no violation should occur. Upsert is a typical case but
it would be equally valid if it's an RI constraint and the transaction
verified that the RI constraint is satisified before inserting or
updating. If a concurrent transaction breaks the constraint for this
insert and the insert gets a constraint violation then it ought to get
a serialization failure since the constraint failure can't occur in a
serialized execution order.

But shouldn't the Read-Write dependency graph already be picking this
up? IF you've previously read a row and someone updates it and then
you try to lock it for updates it should be considering this a
serialization failure.

--
greg

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Andrew Gierth 2014-12-30 18:42:00 9.4 and reproducible "ERROR: could not read block 0 in file..."
Previous Message Merlin Moncure 2014-12-30 16:15:15 Re: BUG #12330: ACID is broken for unique constraints

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2014-12-30 17:26:41 Re: What exactly is our CRC algorithm?
Previous Message Heikki Linnakangas 2014-12-30 16:59:17 Re: Documentation of bt_page_items()'s ctid field