Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y5n3R-0001wP-1i for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Dec 2014 03:01:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Y5n3Q-0004w0-GY for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Dec 2014 03:01:04 +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 1Y5n3N-0004vm-DO for pgsql-hackers@postgresql.org; Tue, 30 Dec 2014 03:01:01 +0000 Received: from nm24-vm4.bullet.mail.ne1.yahoo.com ([98.138.91.184]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Y5n3E-0004t5-KX for pgsql-hackers@postgresql.org; Tue, 30 Dec 2014 03:00:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ymail.com; s=s2048; t=1419908451; bh=2JYiNEvs//Ah9TZSQUKuODfa3gp+t9ToLr1LrSzu0KI=; h=Date:From:Reply-To:To:Cc:In-Reply-To:References:Subject:From:Subject; b=YkEhYaI49lUj+nTJgcv2mNCHb/5u1lZKuTa0Rgt9Q/+f1DYrsrUpvmJ/0qwWvNH9sBFtzA9a3jJZ92cD7PKP3fp7cGksFEbXCsFoWO0zRAiWfA4NapschidlNHv/nROlfI8Tz9grCv5SfWN1OxkyuIvESR+dh+KNIg2ZxoQbVCw7aNIakUqIXEjODaTTWUqlv49rYFKDt7/xzM1+p5fwz8A5Rk5Ha7x6IkV0FVlS73TCnJ29w4XfHQVLP4tyxr2LvuYubPjiPKU91MexEkKBDaycK3KtyReJcEfgtzxd4Fm0cGpMlS+YxpsG7OelSKv60ippgSBIT8r3J9J21OomyQ== DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s2048; d=ymail.com; b=Q8gNQod9TPWkw9/91fHRZ3h+r7NknJI/QSai3dMl9/QXPpHPBd7pX3MWNcElwHIY/b9lFVLnfG247yVj/dZZmI2qpfDnHXtYo5Sxqwlzx38dSHOwgx4UPXIj0KVXd3YV1QA32fwkOnp0BVo3qbOQsRSQvpVcuzFSdgirUgxObgkXtujBjwm3tR/RlnwiJd70ki6d2jehaLmVU6VQbl1jrymYhKro6iz+3J5K8M327sdBcM9z5RkA1SCAsegl+rXGvIFBspxMkuG4YxZwqgRkMw7fEiHjmyh/bfZ7Rgc7JgKi0+S6vTUtSEJ47W5yncfgOEXLglXYWiMtTHEkQEyGZg==; Received: from [98.138.101.130] by nm24.bullet.mail.ne1.yahoo.com with NNFMP; 30 Dec 2014 03:00:51 -0000 Received: from [98.138.88.237] by tm18.bullet.mail.ne1.yahoo.com with NNFMP; 30 Dec 2014 03:00:51 -0000 Received: from [127.0.0.1] by omp1037.mail.ne1.yahoo.com with NNFMP; 30 Dec 2014 03:00:51 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 36710.33238.bm@omp1037.mail.ne1.yahoo.com X-YMail-OSG: 9WOveNIVM1lkTmdstUNkj56bB2YO6yQUW4JrIKT9NI7TXbASm5HjO4Ij5MbV0pD 1tgEOpfrGMgo_56X6Eu3Tl87yf_pq4X9V03mI1Yqgo0qzDZVif9jCwfipe8Cx2Bd8yDNTpsqnNNz pXXF9LuAa6vpWmD8yPyd8eTWqqsKHF53JHEzf1_K1lDjvtun_WsjUNtSyNQcP8hgkLjsDY5WG18I Kj9QmZRcjDhy1ZHsW0XV23KezA.NImlpsuLk4teiUsS1RZiG012pg.6wpLvVVnDRVFVQD3jh04KT 4opZ4yxAiVG2Rz5CdhxGvi1cOZtBVyEceXCLyERvCNBrG_jCapjmR6PGhK49nIwyDvlS_daki.Kv 14PkLuQkWvxFXYSHsPLe1EhubWqqKpiLA8mG.rpP.t4ROGCPil1m.u6Mp68nEmz4nMEwk2bevSve 7qSHKQz7obSJkeOGcMmvxukT5JOqLG3MvFYTRGQdFN_EmQALwJQhP.hMSWCuSJ4GqrKl0tzCyCzK CYLI_dDYY3Kg6lQUJftx32ID5fPsmAWk4.XeTfj2O.aOShNChN0XilcLBSIBrCg-- Received: by 98.138.105.244; Tue, 30 Dec 2014 03:00:50 +0000 Date: Tue, 30 Dec 2014 03:00:43 +0000 (UTC) From: Kevin Grittner Reply-To: Kevin Grittner To: Jim Nasby , Merlin Moncure , Greg Stark Cc: Tom Lane , Josh Berkus , "nikita.y.volkov@mail.ru" , "pgsql-hackers@postgresql.org" Message-ID: <1499898951.1513980.1419908444000.JavaMail.yahoo@jws10072.mail.ne1.yahoo.com> In-Reply-To: <54A1F1B1.40002@BlueTreble.com> References: <54A1F1B1.40002@BlueTreble.com> Subject: Re: BUG #12330: ACID is broken for unique constraints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Length: 3378 X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Jim Nasby wrote: > On 12/29/14, 10:53 AM, Kevin Grittner wrote: >> Merlin Moncure 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. > > As for missing details like the duplicated key value, is there a > reasonable way to add that as an errdetail() to a serialization > failure error? Sure. What we've been discussing is the case where a unique index is checked for a duplicate with visibility which would cause it to fail; whether, at transaction isolation level of serializable, to check to see if the committed transaction which created the existing entry overlaps the entry checking for duplicates, and use a different SQLSTATE. Anything available for display in the detail currently would still be available. We give different detail messages for different types of serialization failures; it would seem a little silly not to mention the table and the duplicate values for this type of serialization failure. My guess is that in production this would be completely ignored by the software, but logging it might be helpful in tuning. > We do still have to be careful here though; you could still have > code using our documented upsert methodology inside a serialized > transaction. For example, via a 3rd party extension that can't > assume you're using serialized transactions. Would it still be OK > to treat that as a serialization failure and bubble that all the > way back to the application? If the current upsert function example were used, unmodified, by serializable transactions with the suggested changes, it would not loop back for another try within the function, but generate a serialization failure for the transaction as a whole. If there was a framework watching for that and retrying transactions when it is seen, the transaction would start over and see the new state and behave correctly. Without the change I'm proposing, I bet it would loop endlessly, until interrupted. [tries it] Yep, there it is. All the hand-wringing about how we might break existing applications is entirely backwards. Under either repeatable read or serializable that technique goes to 100% of one CPU until you cancel it -- completely broken. If it generated a serialization failure the code in our docs would throw the serialization failure out to the client, which (in most environments using serializable transactions, or even repeatable read) would retry the transaction from the beginning, with much less pain. It makes me wonder whether it would be better to generate the serialization failure for both repeatable read and serializable, since those are the cases where the sample code in our docs generates the endless loop. > As part of this, we should probably modify our upsert example so > it takes transaction_isolation into account... Probably. -- Kevin Grittner EDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers