Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YisPA-0001Ts-6P for pgsql-bugs@arkaria.postgresql.org; Thu, 16 Apr 2015 22:37:04 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YisP9-0006vO-GC for pgsql-bugs@arkaria.postgresql.org; Thu, 16 Apr 2015 22:37:03 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YisP8-0006vH-D1 for pgsql-bugs@postgresql.org; Thu, 16 Apr 2015 22:37:02 +0000 Received: from mail-wg0-f42.google.com ([74.125.82.42]) by makus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1YisP0-0005r5-JL for pgsql-bugs@postgresql.org; Thu, 16 Apr 2015 22:37:00 +0000 Received: by wgsk9 with SMTP id k9so95860411wgs.3 for ; Thu, 16 Apr 2015 15:36:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=UjFV1T7ItFQ95gM+y9oBHBuzPG3yL8nmoIoLJxkSTmo=; b=PUZ0g9wOAwCY5wEdApXoySXsfjurzDca7VRr5p1/AZBmBGEACbMEXUyo0Nzmlb+ryu Yng9+IbWDdK9KxHg4lo8jjPnD5+wLduTybqBWbC/x/M7/+ZV0A30IKBo4DK7bLV4fHS+ AZrCPAfjkFe+G+gEHCmQFU6oAFuTdfmUV+dV9srkqCKOa9iWNDIQ1YmBb19VOiYMd997 L9kUqxnKdGpL4qNuNm+m30bJEKXuGW2Pgv1IPjG7aRUqjKYx+cHBW4K8kqb2ZOr/u2sv O/jRnxWi2ixXH+1aOxcMj+wsCzhW6Ny1MHUcrWTFeehqGYooVjLfS+QY09tjXa/VjvBe xKrQ== X-Gm-Message-State: ALoCoQlbKxNXnNXS7PRmo9SDXjAW8oRlKMrWtOwWNDF5hHH/KWPU8L/y+Onb4k0PrxouN58bUFXmTq3qZ2aqvViH7Nxg6GBtSQDvzz/ZFAzTJURGJfJf2X/thrYyIW0Y6Q0Sersbue7/NVwuoTqiy/Z2EUlbKlLQowFHtsxUziceKkBwZel/0X2IA79Tehll1PZXeRNoqmK5 X-Received: by 10.180.84.130 with SMTP id z2mr9182397wiy.42.1429223811300; Thu, 16 Apr 2015 15:36:51 -0700 (PDT) Received: from [10.137.2.12] (ip-78-45-139-138.net.upcbroadband.cz. [78.45.139.138]) by mx.google.com with ESMTPSA id kr5sm12148980wjc.1.2015.04.16.15.36.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Apr 2015 15:36:49 -0700 (PDT) Message-ID: <5530397F.5020003@2ndquadrant.com> Date: Fri, 17 Apr 2015 00:36:47 +0200 From: Tomas Vondra User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: pgsql-bugs@postgresql.org Subject: Re: BUG #13073: Uniqueness constraint incorrectly reports constraint violations References: <20150416200334.5200.85645@wrigleys.postgresql.org> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 04/16/15 23:16, David Portas wrote: > On 16 April 2015 at 21:39, David G. Johnston 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