在High Performance Java Persistence book 的 6.3.3.3 部分中写道,丢失更新现象在 MySQL 可重复读取隔离级别中是可能的。这是屏幕截图:
假设如下(隔离级别为 REPEATABLE READ):
tx1 | tx2
-----------------------------------------------------------------------------------
START TRANSACTION; |
SELECT * FROM test WHERE id = 1; |
( say, DB_TRX_ID = 7 at this moment) |
|
| START TRANSACTION;
| SELECT * FROM test WHERE id = 1;
| UPDATE test SET name="x" WHERE id = 1;
| COMMIT;(say, makes DB_TRX_ID = 10)
|
UPDATE test SET name="y" WHERE id = 1;|
COMMIT;
问题:
在 tx1 提交时,MVCC 会检测到行版本(DB_TRX_ID)不再等于 7(而不是 10)并执行回滚?或者提交将成功导致丢失更新?