mysql特性:semi consistent read

先看看官方的说法:
semi consistent read

A type of read operation used for UPDATE statements, that is a combination of read committed and consistent read. When an UPDATE statement examines a row that is already locked, InnoDB returns the latest committed version to MySQL so that MySQL can determine whether the row matches the WHERE condition of the UPDATE. If the row matches (must be updated), MySQL reads the row again, and this time InnoDB either locks it or waits for a lock on it. This type of read operation can only happen when the transaction has the read committed isolation level, or when the innodb_locks_unsafe_for_binlog option is enabled.


简单来说,semi-consistent read是read committed与consistent read两者的结合。一个update语句,如果读到一行已经加锁的记录,此时InnoDB返回记录最近提交的版本,由MySQL上层判断此版本是否满足update的where条件。若满足(需要更新),则MySQL会重新发起一次读操作,此时会读取行的最新版本(并加锁)。


semi-consistent read只会发生在read committed隔离级别或以下,或者是参数innodb_locks_unsafe_for_binlog被设置为true。


semi consistent read作用情形:
1、RC、RU模式下,或者 innodb_locks_unsafe_for_binlog = 1
2、先执行非UPDATE SQL,后执行UPDATE,不会阻塞。如果先执行UPDATE,后执行其他非UPDATE SQL,则还是会加锁
3、只影响有实际存在的行,不存在的行也OK
 


我的理解:
在rc级别或以下级别(ru),或者 innodb_locks_unsafe_for_binlog = 1(RR) 这三种情况下,会发生semi_consistent_read.
因为innodb是行级锁,如果字段没有索引,在加锁时,会上升为表锁.此时,如果s1执行加锁任何操作,s2执行update操作,在s2的update条件中如果在s1中没有行锁,将不会堵塞s2.原理是:s2发起的update,有mysql上层根据update条件判断是否满足,若条件中没有行锁,则mysql会重新发起一次读操作,并在update后加锁;

同理:如果列是有索引存在的.innodb会自动产生的是行锁,所以semi_consistent_read的效能也就没有什么意义..
所以.semi_consistent_read只发生在没有索引的列,或者有全表锁的情况;只要存在update的数据上有行锁的,semi_consistent_read就失效;


参考:http://blog.csdn.net/nanaranran/article/details/52229383

 

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/20892230/viewspace-2127478/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/20892230/viewspace-2127478/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值