pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedWrite skew anmalies are found in SERIALIZABLE isolation
4+ messages / 3 participants
[nested] [flat]
* Write skew anmalies are found in SERIALIZABLE isolation
@ 2019-10-03 15:33 张舒燕 <51184501183@stu.ecnu.edu.cn>
0 siblings, 1 reply; 4+ messages in thread
From: 张舒燕 @ 2019-10-03 15:33 UTC (permalink / raw)
To: pgsql-bugs <pgsql-bugs@lists.postgresql.org>
When we set the isolation level to SERIALIZABLE, we observed some wirte skew anmalies.
In order to simplify the problem, suppose there are only two items, i.e., X and Y, which are initialized with positive values. The first kind of transactions read X and Y, then write X = X - (X+Y) * 0.9. The second kind of transactions read X and Y, then write Y = Y - (X+Y) * 0.9. These transactions execute concurrently. If serializability is guaranteed, the value of (X+Y) must be a positive number.
In our test, there are two tables, i.e., xtable and ytable. The values in these two tables are all positive. Each table has 50 tuples. In our experiments, there are 50 test threads where each thread establishes a separate database connection.
Transaction 1:
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
X ß select xcol from xtable where id= 3;
Y ß select ycol from ytable where id=3;
update ytable set ycol = ycol-(X+Y) * 0.9 where id =3;
COMMIT
Transaction 2:
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
X ß select xcol from xtable where id=3;
Y ß select ycol from ytable where id=3;
update xtable set xcol = xcol-(X+Y) * 0.9 where id =3;
COMMIT
At last, we run: select xtable.id from xtable join ytable using (id) where xtable.xcol + ytable.ycol < 0. Sometimes the result set is not empty, which means the serializability is violated. We observe this issue with Test1.java.
If each transaction only read one item with secondary index and write another item with primary index, write skew anomalies are more likely to occur.
Transaction 1:
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
X ß select xcol from xtable where id=3;
update ytable set ycol = ycol-ycol * 0.9 - X * 0.9 where id =3;
COMMIT
Transaction 2:
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
Y ß select ycol from ytable where id=3;
update xtable set xcol = xcol-xcol * 0.9 - Y * 0.9 where id =3;
COMMIT
At last, we run the same join SQL, and more anomalies can be found. The corresponding test program is Test2.java.
If you need any additional information, please tell us.
Bset regards,
Shuyan Zhang, ECNU
Attachments:
Test2.java (application/octet-stream, 3.5K) download
Test1.java (application/octet-stream, 3.4K) download
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Write skew anmalies are found in SERIALIZABLE isolation
@ 2019-10-03 21:05 Peter Geoghegan <pg@bowt.ie>
parent: 张舒燕 <51184501183@stu.ecnu.edu.cn>
0 siblings, 1 reply; 4+ messages in thread
From: Peter Geoghegan @ 2019-10-03 21:05 UTC (permalink / raw)
To: 张舒燕 <51184501183@stu.ecnu.edu.cn>; +Cc: pgsql-bugs <pgsql-bugs@lists.postgresql.org>
On Thu, Oct 3, 2019 at 9:18 AM 张舒燕 <51184501183@stu.ecnu.edu.cn> wrote:
> When we set the isolation level to SERIALIZABLE, we observed some wirte skew anmalies.
What version of PostgreSQL did you test? Does this bug affect all versions?
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Write skew anmalies are found in SERIALIZABLE isolation
@ 2019-10-04 01:36 张舒燕 <51184501183@stu.ecnu.edu.cn>
parent: Peter Geoghegan <pg@bowt.ie>
0 siblings, 1 reply; 4+ messages in thread
From: 张舒燕 @ 2019-10-04 01:36 UTC (permalink / raw)
To: Peter Geoghegan <pg@bowt.ie>; +Cc: pgsql-bugs <pgsql-bugs@lists.postgresql.org>
We have tested versions of 9.4.0, 9.6.0, 10.0, 11.0 and 11.5 and found the Bug on all of them.
We have wrong statements in the last email.
"If each transaction only read one item with secondary index and write another item with primary index, write skew anomalies are more ( -> less) likely to occur."
"At last, we run the same join SQL, and more ( -> less) anomalies can be found. The corresponding test program is Test2.java."
There are less anomalies can be found in the second situation using Test2.java.
And some mistakes in our test programs have been fixed.
Best regards ,
Shuyan Zhang, ECNU
------------------ Original ------------------
From: "Peter Geoghegan"<pg@bowt.ie>;
Date: Fri, Oct 4, 2019 05:05 AM
To: "张舒燕"<51184501183@stu.ecnu.edu.cn>;
Cc: "pgsql-bugs"<pgsql-bugs@lists.postgresql.org>;
Subject: Re: Write skew anmalies are found in SERIALIZABLE isolation
On Thu, Oct 3, 2019 at 9:18 AM 张舒燕 <51184501183@stu.ecnu.edu.cn> wrote:
> When we set the isolation level to SERIALIZABLE, we observed some wirte skew anmalies.
What version of PostgreSQL did you test? Does this bug affect all versions?
--
Peter Geoghegan
Attachments:
Test1.java (application/octet-stream, 3.5K) download
Test2.java (application/octet-stream, 3.7K) download
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Write skew anmalies are found in SERIALIZABLE isolation
@ 2019-10-04 07:28 Konstantin Knizhnik <k.knizhnik@postgrespro.ru>
parent: 张舒燕 <51184501183@stu.ecnu.edu.cn>
0 siblings, 0 replies; 4+ messages in thread
From: Konstantin Knizhnik @ 2019-10-04 07:28 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org
On 04.10.2019 4:36, 张舒燕 wrote:
> We have tested versions of 9.4.0, 9.6.0, 10.0, 11.0 and 11.5 and found
> the Bug on all of them.
>
> We have wrong statements in the last email.
> "If each transaction only read one item with secondary index and write
> another item with primary index, write skew anomalies are more ( ->
> less) likely to occur."
> "At last, we run the same join SQL, and more ( -> less) anomalies can
> be found. The corresponding test program is Test2.java."
> There are less anomalies can be found in the second situation using
> Test2.java.
>
> And some mistakes in our test programs have been fixed.
>
> Best regards ,
> Shuyan Zhang, ECNU
I do not think that this problem is somehow related with "write skew
anomalies".
The type of "col" is decimal, but you are extracting it as "double",
making conversion and loosing precision.
Then you perform some manipulations using Java BigDecimal class, convert
result to string (which also does some rounding) and subtract this value
from the column.
As a result of this conversions your original assumption that
(x+y)*0.9 < (x+y) may be wrong.
Please try to reproduce the problem using integer type and I am almost
sure that you will not able to get this anomalies.
> ------------------ Original ------------------
> *From: * "Peter Geoghegan"<pg@bowt.ie>;
> *Date: * Fri, Oct 4, 2019 05:05 AM
> *To: * "张舒燕"<51184501183@stu.ecnu.edu.cn>;
> *Cc: * "pgsql-bugs"<pgsql-bugs@lists.postgresql.org>;
> *Subject: * Re: Write skew anmalies are found in SERIALIZABLE isolation
> On Thu, Oct 3, 2019 at 9:18 AM 张舒燕 <51184501183@stu.ecnu.edu.cn> wrote:
> > When we set the isolation level to SERIALIZABLE, we observed some
> wirte skew anmalies.
>
> What version of PostgreSQL did you test? Does this bug affect all
> versions?
>
> --
> Peter Geoghegan
--
Konstantin Knizhnik
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2019-10-04 07:28 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-10-03 15:33 Write skew anmalies are found in SERIALIZABLE isolation 张舒燕 <51184501183@stu.ecnu.edu.cn>
2019-10-03 21:05 ` Peter Geoghegan <pg@bowt.ie>
2019-10-04 01:36 ` 张舒燕 <51184501183@stu.ecnu.edu.cn>
2019-10-04 07:28 ` Konstantin Knizhnik <k.knizhnik@postgrespro.ru>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox