Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WOY0p-0001sw-L8 for pgsql-bugs@arkaria.postgresql.org; Fri, 14 Mar 2014 19:43:23 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WOY0p-00011U-4t for pgsql-bugs@arkaria.postgresql.org; Fri, 14 Mar 2014 19:43:23 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WOY0n-00011N-Vh for pgsql-bugs@postgresql.org; Fri, 14 Mar 2014 19:43:22 +0000 Received: from nm24-vm5.bullet.mail.ne1.yahoo.com ([98.138.91.246]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WOY0i-0008E1-AN for pgsql-bugs@postgresql.org; Fri, 14 Mar 2014 19:43:19 +0000 Received: from [98.138.226.176] by nm24.bullet.mail.ne1.yahoo.com with NNFMP; 14 Mar 2014 19:43:14 -0000 Received: from [98.138.101.170] by tm11.bullet.mail.ne1.yahoo.com with NNFMP; 14 Mar 2014 19:43:14 -0000 Received: from [127.0.0.1] by omp1081.mail.ne1.yahoo.com with NNFMP; 14 Mar 2014 19:43:14 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 561108.56972.bm@omp1081.mail.ne1.yahoo.com Received: (qmail 44475 invoked by uid 60001); 14 Mar 2014 19:43:14 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ymail.com; s=s1024; t=1394826194; bh=k3T5SzupF9U+k8m3+RGNsGFELUHn3qLStDVTVFDs7LA=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=vg463TJxm15rkH6K7Y5B7GjJdfJeBVKfcocWJs7yowcKXGIMDUVdzU8ODsCSLWl9KK87XFcQDIY1fLBISl4wp8tzzHLKub1/pgZdHSSkewvaCFWCA3OsncQxBJy0oj6Ih4FOFmvN03QXsRi1L87yda6BVCnEIyw3tOcYZZygPL4= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=ymail.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=IWlYIG/EJvIX5nNq9Nb4oijvGwOgvpTnKEFdLX/jiVe3f7t4oX9awocopoJBUkXaJpyoVK/DZewF1/HK3J0cav8ej26klvsz5WHlk4ppTctNZYY9BM3iSOTBC0NmQaJliDxNBmGf+240UEu8hkMxVAUBlJXfNfADGMdP6wtu2zk=; X-YMail-OSG: cCqvcakVM1l.Bq4V2YI_Sl19zTwx058miiJbPJDMOedTJrv _Q8_QBw8ieHojU8aNLm8QxQqMImnYKO1HqPTvslhlrZfZk2.heDeYP2EegMG 1BI8BH0b9yvhX_9CttborKNdGEADzc0d.xraHYRYs6VyzeUTLDLO5ytEi6do k5TuUC.lv43E7ViiVChuGOy17sXQiCBL4feOyy97YmsWNW7d71zJsQsYdswE HTLtFRf1NP_ku6k21czBpSHK3Dc8Jm.HcF6nvAG2Y.XpK_TuJWL6_Hw7aeFL jJ8S.AFWvedARJ9bK0Q7wfODKT_.nQmIQi2aZQOderRrBfdWniQDqwTjKzxj S7LiVpPk.Xpz3Jc0vTi6AuBbtgVQMRo7A_oY2QC79d_Zt70mSYY5kvo3X7oc ZxwI.3doAos6n2sKSS49U3MsYO1pZMmJq2KL4RCWztFQs9yEsq0YaMb9J_dC goAuUlQbqyPoib0M5tZxU_6oRAuzqxXKFl4p4iN4DJTLNA_aEG9qKADsbfa9 fbKWbc4N7LyWyinqJSkt.YEF8Pepyz.BqL.N7ajd0HYe_BrncS9hcNLXgcNq eu56uIbKM84u0TQ.BfvmVoHCVn0CVtqGRGBn9GqOIRTXBCClQGang2CdBzWx dir3ibumQdVza0202gOSyB4mCIInPsVgiI2pYSPNCndrHbNWDja6xle9zDYJ d71oNMb8bylVTalSEi_Yl Received: from [24.178.25.147] by web122305.mail.ne1.yahoo.com via HTTP; Fri, 14 Mar 2014 12:43:14 PDT X-Rocket-MIMEInfo: 002.001, RGF2aWQgSm9obnN0b24gPHBvbG9ib0B5YWhvby5jb20.IHdyb3RlOgo.IFRvbSBMYW5lLTIgd3JvdGUKPj4gbXNjb3R0QCB3cml0ZXM6Cgo.Pj4gLS0gVGhlIGZvbGxvd2luZyBzZWVtcyB0byB2aW9sYXRlIHRoZSBmdW5kYW1lbnRhbCBndWFyYW50ZWUgb2YKPj4.IElTT0xBVElPTiBMRVZFTCBTRVJJQUxJWkFCTEUgaW4gdGhhdCB0aGUgdHdvIHRyYW5zYWN0aW9ucyBiZWxvdwo.Pj4gZG8gbm90IGJlaGF2ZSB0aGUgc2FtZSBhcyBpZiB0aGV5IHdlcmUgcnVuIHNlcmlhbGx5Lgo.Pgo.PiBJIG11c3QgYmUgbWkBMAEBAQE- X-Mailer: YahooMailWebService/0.8.178.641 References: <20140221002001.29130.27157@wrigleys.postgresql.org> <14879.1392954389@sss.pgh.pa.us> <1392965881288-5793000.post@n5.nabble.com> Message-ID: <1394826194.18022.YahooMailNeo@web122305.mail.ne1.yahoo.com> Date: Fri, 14 Mar 2014 12:43:14 -0700 (PDT) From: Kevin Grittner Reply-To: Kevin Grittner Subject: Re: Re: BUG #9301: INSERT WHERE NOT EXISTS on table with UNIQUE constraint in concurrent SERIALIZABLE transactions To: David Johnston , "pgsql-bugs@postgresql.org" In-Reply-To: <1392965881288-5793000.post@n5.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: 0.7 (/) 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 David Johnston wrote: > Tom Lane-2 wrote >> mscott@ writes: >>> -- The following seems to violate the fundamental guarantee of >>> ISOLATION LEVEL SERIALIZABLE in that the two transactions below >>> do not behave the same as if they were run serially. >> >> I must be missing something ... what about the duplicate-key >> error is not what you would expect if the two transactions had >> been run serially? >> >> BTW, the fundamental guarantee is not what you said above.=C2=A0 It >> is that you will *either* get the same results as if the >> transactions had been run in some unspecified serial order, *or* >> you will get a serialization error.=C2=A0 There is certainly no >> guarantee about which of these cases ensues. > My reading is that if run serially the second function call > results in a select returning zero records (exists returns true, > then not-ed to a constant false in the where clause) and thus no > insert is attempted and thus no duplicate key error - the record > from the first transaction remains as-is and the second is > effectively a no-op. > > So the fact the serializable versions fails is correct but it > fails "incorrectly" since a serial execution could never fail > with a duplicate key error.=C2=A0 Thus neither a possible unspecified > serial order result (dup being an impossible one) nor a > serialization error occurred which is contrary to the guarantee > that you state. > > Now, the fact is the serialization case correctly fails but from > an API perspective immediate retry makes no sense for duplicate > key failure while it does for serialization failure. This issue has been noted in the literature since at least 2007[1]. In the static code analysis of academic and financial systems at Indian Institute of Technology Bombay which had been relying on snapshot isolation for transactional integrity they initially flagged many possible sources of data corruption from serialization failure which turned out not to actually be possible due to primary keys, unique indexes, or foreign keys.=C2=A0 After considering such issues they were left with only two real risks in each of the systems, and were only able to find actual data corruption of one of those in each system. If there were a cheap and reliable way to turn violations of these constraints into serialization failures where appropriate, I agree that it would be better to do so.=C2=A0 I have not been able to see any way to do that, but am all ears if anyone else has an idea.=C2=A0 (Note the constraints of cheap and reliable; we could allow the SSI mechanism to generate SIReadLocks during constraint enforcement, but it's not clear that it would always find a serialization error before the constraint caused an error, and the overhead might be significant.) The actual guarantee provided is more like: "The behavior of any set of successfully committed concurrent serializable transactions will be consistent with some unspecified serial order of execution of those transactions."=C2=A0 Constraints may terminate a transaction before the serializable snaphsot isolation mechanism is able to recognize a problem and cancel a transaction with a different SQLSTATE, but the guarantee should prevent any serialization anomalies from appearing in the database.=C2=A0 It does present a challenge in terms of knowing whether a constraint validation like "duplicate key" indicates a situation which can be automatically re-tried.=C2=A0 If that is of paramount importance one could implement the logic for preventing duplicate keys or enforcing foreign keys in triggers using serializable transactions, but that would come with a heavy price in both maintenance effort and performance. -- Kevin Grittner EDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company [1] http://www.vldb.org/conf/2007/papers/industrial/p1263-jorwekar.pdf Automating the Detection of Snapshot Isolation Anomalies by Sudhir Jorwekar, Krithi Ramamritham, Alan Fekete, S. Sudarshan VLDB =E2=80=9807, September 23-28, 2007, Vienna, Austria. --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs