pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: pgsql-bugs@postgresql.org
Subject: Re: BUG #13073: Uniqueness constraint incorrectly reports constraint violations
Date: Fri, 17 Apr 2015 00:36:47 +0200
Message-ID: <5530397F.5020003@2ndquadrant.com> (raw)
In-Reply-To: <CALqCgwQck9iTWpXgiCYQqumqfu3qarXUwVRuAp6RG+Ek0zUG-w@mail.gmail.com>
References: <20150416200334.5200.85645@wrigleys.postgresql.org>
	<CAKFQuwbtgtz2XGOgmObdwXjyVt7aJTCYv4pBB2DToHhsAGCNOA@mail.gmail.com>
	<CALqCgwQck9iTWpXgiCYQqumqfu3qarXUwVRuAp6RG+Ek0zUG-w@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>



On 04/16/15 23:16, David Portas wrote:
> On 16 April 2015 at 21:39, David G. Johnston <david.g.johnston@gmail.com> wrote:
>>
>> You are, not unexpectedly, assuming that constraints are evaluated only
>> after all rows has been processed - i.e., post-statement completion.  While
>> this is possible (see below) it is not the default behavior.  By default, as
>> each row is updated all of the relevant constraints are checked to see if
>> any have been violated.
>>
>
> Thanks. It's interesting that the default behaviour is to compromise
> ACID compliance with a result that is, logically speaking,
> non-deterministic. This appears to be inconsistent with the ISO SQL
> standard [1] and with other SQL DBMSs.

I don't see how this compromises ACID compliance. If anything, it makes 
the consistency checks more strict (not allowing violated constraint 
mid-transaction).

As for the SQL standard compliance, the documentation [1] says this:

     When a UNIQUE or PRIMARY KEY constraint is not deferrable,
     PostgreSQL checks for uniqueness immediately whenever a row is
     inserted or modified. The SQL standard says that uniqueness should
     be enforced only at the end of the statement; this makes a
     difference when, for example, a single command updates multiple key
     values. To obtain standard-compliant behavior, declare the
     constraint as DEFERRABLE but not deferred (i.e., INITIALLY
     IMMEDIATE). Be aware that this can be significantly slower than
     immediate uniqueness checking.

In other words, this is a known difference, this default behavior was 
chosen because

  (a) it has performance benefits
  (b) is more appropriate for most cases
  (c) does *not* compromise any consistency guarantees (but may cause
      false positives), and
  (d) there's a way to make it standard-compliant behavior by setting
      the constraint DEFERRABLE.


[1] http://www.postgresql.org/docs/9.1/static/sql-createtable.html

--
Tomas Vondra                  http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (6+ messages)  latest in thread

Message-ID: <5530397F.5020003@2ndquadrant.com>
Permalink:  ../5530397F.5020003@2ndquadrant.com/
Also on:    postgresql.org/message-id/5530397F.5020003@2ndquadrant.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tomas.vondra@2ndquadrant.com
  Subject: Re: BUG #13073: Uniqueness constraint incorrectly reports constraint violations
  In-Reply-To: <5530397F.5020003@2ndquadrant.com>
  References: <20150416200334.5200.85645@wrigleys.postgresql.org> <CAKFQuwbtgtz2XGOgmObdwXjyVt7aJTCYv4pBB2DToHhsAGCNOA@mail.gmail.com> <CALqCgwQck9iTWpXgiCYQqumqfu3qarXUwVRuAp6RG+Ek0zUG-w@mail.gmail.com> <5530397F.5020003@2ndquadrant.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox