Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y4YUy-0006ZF-BO for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Dec 2014 17:16:24 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Y4YUx-0001tl-Ou for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Dec 2014 17:16:23 +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 1Y4YUw-0001tf-7w for pgsql-hackers@postgresql.org; Fri, 26 Dec 2014 17:16:22 +0000 Received: from nm19-vm5.bullet.mail.ne1.yahoo.com ([98.138.91.241]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Y4YUs-0000R0-9i for pgsql-hackers@postgresql.org; Fri, 26 Dec 2014 17:16:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ymail.com; s=s2048; t=1419614176; bh=W7SCWEgxmmmanw1ea3ZBCgz8lH7ZTS4G0Sdct16dvpg=; h=Date:From:Reply-To:To:Cc:In-Reply-To:References:Subject:From:Subject; b=QzlHfXTk9S3fDaVGkbMFFq1Zv5yuwln6KjY2UlY8DvH73JpyD59NAGoxAjkQbvrWpzp+RjRRZyuWNx7A/7JTWIfEnr+dsDbf4M6XPYrCdoRX143oy5/TncLZdBYu6mqxNCiMsZPidQtvvytk42LO1lCGew9IExqi2lES4Sp2v2WRwmwKtSI7M+kAnCOB6bMxXCs9IthcQFf6REuEyM3sqwuVT4Z6bN/YTP+yf3a9lXo9k+B3tECjMl7UZ7cZNu1ISIuak4A+8iSeCLNE4tGgXoPapknNojy73hQ48sPWSTGyrX14XxOWWO6b2RkqPSffWfEUU0p+xLGE/TN0SDA2vA== DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s2048; d=ymail.com; b=qnSg460l3Dpbm+Q4lUFQ53GQPj58sTK/V/Ciez9w++Xj9eYNRKrHed7nLSZ82bwGDIN+yd9QJWeGMTGvBuLfQiU4EYDhOkzFAEGYa8eub02HPZ1J90Ay7z3aTe0fC3xF/nZaKHIGvQxIoBGp3KozYJkXf8Ya+2xg8Hvo3YpDjR7Meq0Q9i2SVP9hpfXD/zOrXb56GfgoMtrlMY3LxiGWXcl/wDJmcqOfkV6MsOEmNq8xJgEqhaRvwVSUK9O1TM3aLc7r+9XsKREV2qnJMPDUwoe0RfFCiEFR1llx0ls22eO9qUcEzruf1EStRdoGrpPuJXXRxA9Im9jmk6w0ZLtTSA==; Received: from [98.138.100.118] by nm19.bullet.mail.ne1.yahoo.com with NNFMP; 26 Dec 2014 17:16:16 -0000 Received: from [98.138.89.240] by tm109.bullet.mail.ne1.yahoo.com with NNFMP; 26 Dec 2014 17:16:16 -0000 Received: from [127.0.0.1] by omp1013.mail.ne1.yahoo.com with NNFMP; 26 Dec 2014 17:16:16 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 866012.37249.bm@omp1013.mail.ne1.yahoo.com X-YMail-OSG: Uz4hCKQVM1kE2qRrcocW0Fz_BKktZpvq11Bwnnt_kZXsaJnoeNptI6.K.PyLnfI x1rTxfzADh7.2KTIvDVMK0Ql0fDOrN3X4oBg.sc9R29It49yxrGoeZLZX8o1gwggn3pwvlVFrwLy LywxjmcESjt.8resKFQSrTXpZ2nSaRDL_mU0fWGVA8fhIe.X.ebeZQLAkxOxW1Axm4I3JfH2EQz. 6bDkgOwXj3ONbVDYWX4fiKgIYxrAHrB_XrkTJWpJ1QI_rxcYDD29JbgSO0i_i6Yf2BkL7yONfS4r rO2B9_J36CxIn2DSRY2wxTVkaCKCAwsZDajuDWv0_g33g8mS18i6intFqSqYcYj.jiWjMvspqZFK Z2O82fhCAqEB39HeVNdswKykPza208EVyJgDSiBgR44ptVPHtPkEEb6IugYcoY6JKZc_nDBDQAxF vnyAR4EB81Gw1T7AxTvzcyfFl.qqN9XBI7eiaKnJtdKPbudyJVgIEoKwm4Zwn0bQ2zh273KQweVh AetKqfeoNnNugMQWptwxdOc9uFZIP52mUjJEmsuuvcKrDF2_FL4gUT.W4Jhg- Received: by 98.138.101.166; Fri, 26 Dec 2014 17:16:16 +0000 Date: Fri, 26 Dec 2014 17:16:15 +0000 (UTC) From: Kevin Grittner Reply-To: Kevin Grittner To: Tom Lane Cc: "nikita.y.volkov@mail.ru" , "pgsql-hackers@postgresql.org" Message-ID: <214229149.918351.1419614175060.JavaMail.yahoo@jws100210.mail.ne1.yahoo.com> In-Reply-To: <31635.1419609041@sss.pgh.pa.us> References: <31635.1419609041@sss.pgh.pa.us> 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: 2326 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 Tom Lane wrote: > Kevin Grittner writes: >> Are there any objections to generating a write conflict instead >> of a duplicate key error if the duplicate key was added by a >> concurrent transaction? > > Yes. This will deliver a less meaningful error code, That depends entirely on whether you care more about whether the problem was created by a concurrent transaction or exactly how that concurrent transaction created the problem. For those using serializable transactions to manage concurrency the former is at least an order of magnitude more important. This is not the first time getting a constraint violation SQLSTATE for the actions of a concurrent serializable transaction has been reported as a bug. Going from memory, I think this might be about the fifth time users have reported it as a bug or potential bug on these lists. People using serializable transactions normally run all queries through common code with will retry the transaction from the start if there is a SQLSTATE starting with '40' (or perhaps picking out the specific codes '40001' and '40P01'). Not doing so for *some* types of errors generated by concurrent transactions reduces the application's level of user-friendliness, and may introduce surprising bugs. In this particular case the OP wants to do one thing if a row with a paricular value for a unique index exists, and something different if it doesn't. If we generate the write conflict for the case that it is concurrently added, it can retry the transaction and do one or the other; if we don't pay attention to that, they need weird heuristics for "the third case". That really is not more meaningful or useful. > *and* break existing code that is expecting the current behavior. Possibly, but my experience is more that failure to behave the way I suggest is biting people and causing them a lot of extra work and pain. I would be fine with limiting the new behavior to serializable transactions, since that seems to be where people want this behavior. It would bring us closer to "the transaction will run as though it were the only transaction running or roll back with a serialization failure" without having to add caveats and exceptions. -- 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