问题分析 首先幻读是什么? 根据MySQL文档上面的定义 The so-called phantom problem occurs within a transaction when the same query produces different sets of rows at different times. For example, if a SELECT is executed twice, but returns a row the second time that was not…
1.结论 在RR的隔离级别下,Innodb使用MVVC和next-key locks解决幻读,MVVC解决的是普通读(快照读)的幻读,next-key locks解决的是当前读情况下的幻读. 2.幻读是什么 事务A,先执行: update table set name=“hh” where id>3; 结果为: OK row xx 表名成功影响多少行数据 事务B,后执行,并且提交: insert into table values(11, uu); commit; 事务A,然后再select一下…
; 原理:将历史数据存一份快照,所以其他事务增加与删除数据,对于当前事务来说是不可见的. 2. next-key 锁 (当前读) next-key 锁包含两部分: 记录锁(行锁) 间隙锁 记录锁是加在索引上的锁,间隙锁是加在索引之间的.(思考:如果列上没有索引会发生什么?) select * from T where number = 1 for update; select * from T where number = 1 lock in share mode; insert update…