我正在阅读有关InnoDB's
隔离级别的内容,这在很大程度上是有道理的,但我不明白为什么是unrepeatable reads
一件坏事?不应该反过来吗?
举些例子:
假设我们有一个用于销售产品的库存列,每次有人购买一件商品时,我们都会从该列中取出一件商品,使用Repeatable read
或serializable
隔离级别不会破坏数据完整性吗?
例如:
TX A: start transaction;
TX B: set session transaction isolation level repeatable read;
TX B: start transaction;
TX A: select stock from products; -- val = 8
TX B: select stock from products; -- val = 8
TX A: update products set stock = stock - 1; -- val = 7
TX B: select stock from products; -- val = 8
TX A: commit
TX B: select stock from products; -- val = 8, incorrect!
TX B: commit;
TX B: select stock from products; -- val = 7
除非它在运行更新时使用正确的值?