Re:Fwd: BUG #17017: Two versions of the same row of records are returned in one query

From: 李可强 <52194501011(at)stu(dot)ecnu(dot)edu(dot)cn>
To: tgl <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-bugs <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re:Fwd: BUG #17017: Two versions of the same row of records are returned in one query
Date: 2021-05-19 05:04:07
Message-ID: tencent_53E42BE16C22D6872833143B@qq.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi Tom,
I think the repeatable read transaction should give priority to see the new version written&nbsp;by itself, e.g., the insertion of the above example. There is no need to return the old version written by committed transactions. The query result fo Session B is very confusing!

------------------&nbsp;Original&nbsp;------------------
From: &nbsp;"刘沛源"<lpy(dot)henu(at)gmail(dot)com&gt;;
Date: &nbsp;Wed, May 19, 2021 09:05 AM
To: &nbsp;"52194501011"<52194501011(at)stu(dot)ecnu(dot)edu(dot)cn&gt;;

Subject: &nbsp;Fwd: BUG #17017: Two versions of the same row of records are returned in one query

&nbsp;

---------- Forwarded message ---------
发件人: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us&gt;
Date: 2021年5月19日周三 00:18
Subject: Re: BUG #17017: Two versions of the same row of records are returned in one query
To: <lpy(dot)henu(at)gmail(dot)com&gt;
Cc: <pgsql-bugs(at)lists(dot)postgresql(dot)org&gt;

PG Bug reporting form <noreply(at)postgresql(dot)org&gt; writes:
&gt; Schema and Initial data:
&gt; Create Table t(a int primary key, b int);
&gt; Insert into t values(1,2);
&gt; Insert into t values(2,3);

&gt; [Time0, SessonA]
&gt;&gt; Begin;
&gt;&gt; set transaction isolation level repeatable read;
&gt;&gt; Select * from t where a=1;

&gt; [Time1, SessonB]
&gt;&gt; Begin;
&gt;&gt; set transaction isolation level read committed;
&gt;&gt; Delete from t where a=2;
&gt;&gt; Commit;

&gt; [Time2, SessonA]
&gt;&gt; Insert into t values(2,4);
&gt;&gt; Select * from t where a=2;

&gt; Here, we expect PostgreSQL Server to return a row:
&gt; 2 3

&gt; However, it returns two rows:
&gt; 2 4
&gt; 2 3

In repeatable read mode, this doesn't surprise me.&nbsp; Session A
surely must return the (2,3) row, since it isn't supposed to
"see" the results of Session B's commit yet.&nbsp; 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".&nbsp; Repeatable read mode meets the
requirements of the SQL spec, but it doesn't guarantee
no anomalies.

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2021-05-19 06:58:19 BUG #17022: SQL causing engine crash
Previous Message David Rowley 2021-05-19 02:13:09 Re: Query with straightforward plan changes and becomes 6520 times slower after VACUUM ANALYZE