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

From: Kevin Grittner <kgrittn(at)ymail(dot)com>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>, Greg Stark <stark(at)mit(dot)edu>
Cc: 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-29 16:53:24
Message-ID: 1511100927.1386218.1419872004754.JavaMail.yahoo@jws100113.mail.ne1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

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 because they provide absolutely (as Tom pointed
> out) zero detail to the application.

That is false. They provide an *extremely* valuable piece of
information which is not currently available when you get a
duplicate key error -- whether the error occurred because of a race
condition and will not fail for the same cause if retried.

> The precise definition of the error is up to us, but I'd rather
> keep it to it's current rather specific semantics.

The semantics are so imprecise that Tom argued that we should
document that transactions should be retried from the start when
you get the duplicate key error, since it *might* have been caused
by a race condition.

I'm curious how heavily you use serializable transactions, because
I have trouble believing that those who rely on them as their
primary (or only) strategy for dealing with race conditions under
high concurrency would take that position.

As for the fact that RI violations also don't return a
serialization failure when caused by a race with concurrent
transactions, I view that as another weakness in PostgreSQL. I
don't think there is a problem curing one without curing the other
at the same time. I have known of people writing their own
triggers to enforce RI rather than defining FKs precisely so that
they can get a serialization failure return code and do automatic
retry if it is caused by a race condition. That's less practical
to compensate for when it comes to unique indexes or constraints.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Adrian Klaver 2014-12-29 17:06:45 Re: Rollback on include error in psql
Previous Message David Johnston 2014-12-29 16:52:53 Re: Rollback on include error in psql

Browse pgsql-hackers by date

  From Date Subject
Next Message Adrian Klaver 2014-12-29 17:16:20 Re: ON_ERROR_ROLLBACK
Previous Message Adrian Klaver 2014-12-29 16:51:14 ON_ERROR_ROLLBACK