Discuss / SQL / 第二次查询仍为空

第二次查询仍为空

Topic source

李涛LT888

#1 Created at ... [Delete] [Delete and Lock User]

事务B在第6步再次读取id=99的记录时,读到的记录仍然为空。why?

我也想问!!

因为Repeatable Read下在同一个事务内的查询都是与事务开始时刻一致,所以在B事务过程中是不会读到期间A中insert的值的

那为什么可以更新呢?既然是同一时刻开始的

长宁特产

#5 Created at ... [Delete] [Delete and Lock User]

因为没有更新,你可以理解为用缓存了

xiao伟iii

#6 Created at ... [Delete] [Delete and Lock User]

如果不是空,那不是和不可重复读一样了吗, 就没有 幻读 这么一说啦?哈哈哈...

xiao伟iii

#7 Created at ... [Delete] [Delete and Lock User]

那有个问题了,如果 A 做的是 更新操作,那 B 能读到更新后的数据吗?有小伙伴测试了吗?

@ xiao伟iii

一开始id = 99的 name 为 Alice

事务 B 第 3 步读到的是 Alice

按照顺序去做,只是事务A 的第 4 步换成了你讲的 update 为 'aaa'; 并执行 5 commit

第 6 步 事务 B 去读,依然是 Alice;

第 7 步 事务 B update 为 ‘bbb’;

第 8 步 读到的则为 bbb;

狼叔叔

#9 Created at ... [Delete] [Delete and Lock User]

REPEATABLE READ避免了不可重复读问题,事务内对同一数据的多次读取都是一致的。

一个事务修改一条数据,其他事务修改同一数据就要等待。

增、删数据时会出现幻读。

不可重复读的重点是修改数据,幻读的重点是增删数据。

事务各自COMMIT后,再查询,各自的修改内容就汇总在一起了。

Read committed is an isolation level that guarantees that any data read was committed at the moment is read. It simply restricts the reader from seeing any intermediate, uncommitted, 'dirty' read. It makes no promise whatsoever that if the transaction re-issues the read, will find the Same data, data is free to change after it was read.

Repeatable read is a higher isolation level, that in addition to the guarantees of the read committed level, it also guarantees that any data read cannot change, if the transaction reads the same data again, it will find the previously read data in place, unchanged, and available to read.

https://stackoverflow.com/questions/4034976/difference-between-read-commited-and-repeatable-read


  • 1
  • 2

Reply