Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lj2Qs-0001px-Ce for pgsql-bugs@arkaria.postgresql.org; Tue, 18 May 2021 16:18:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lj2QL-0003RH-2b for pgsql-bugs@arkaria.postgresql.org; Tue, 18 May 2021 16:18:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lj2QK-0003M7-Rb for pgsql-bugs@lists.postgresql.org; Tue, 18 May 2021 16:18:24 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lj2QI-0006En-OZ for pgsql-bugs@lists.postgresql.org; Tue, 18 May 2021 16:18:23 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 14IGIJ6S3229568; Tue, 18 May 2021 12:18:20 -0400 From: Tom Lane To: lpy.henu@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17017: Two versions of the same row of records are returned in one query In-reply-to: <17017-c37dbbadb77cfde9@postgresql.org> References: <17017-c37dbbadb77cfde9@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Tue, 18 May 2021 13:26:24 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3229566.1621354699.1@sss.pgh.pa.us> Date: Tue, 18 May 2021 12:18:19 -0400 Message-ID: <3229567.1621354699@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > Schema and Initial data: > Create Table t(a int primary key, b int); > Insert into t values(1,2); > Insert into t values(2,3); > [Time0, SessonA] >> Begin; >> set transaction isolation level repeatable read; >> Select * from t where a=1; > [Time1, SessonB] >> Begin; >> set transaction isolation level read committed; >> Delete from t where a=2; >> Commit; > [Time2, SessonA] >> Insert into t values(2,4); >> Select * from t where a=2; > Here, we expect PostgreSQL Server to return a row: > 2 3 > However, it returns two rows: > 2 4 > 2 3 In repeatable read mode, this doesn't surprise me. Session A surely must return the (2,3) row, since it isn't supposed to "see" the results of Session B's commit yet. And it would be mighty surprising for it not to see its own insertion, so you get (2,4) as well. In serializable mode, I'd expect this situation to throw a serialization error, and it does (but you must run BOTH transactions in serializable mode; there are not guarantees with a mix of serializable and non-serializable transactions). So I think the answer is "if you care about this, use serializable mode". Repeatable read mode meets the requirements of the SQL spec, but it doesn't guarantee no anomalies. regards, tom lane