码迷,mamicode.com
首页 > 数据库 > 详细

mysql locking

时间:2018-12-03 12:52:24      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:enc   5.7   ODB   form   sql   func   dex   fun   date   

1. 意向锁

https://dev.mysql.com/doc/refman/5.7/en/innodb-locking.html#innodb-insert-intention-locks

官方文档,意向锁是Innodb为了支持多种粒度锁(表锁+行锁)设计的。

举例:

一个表 tab1

id, name

2, "xxxx"

id是unique key。

事务T1 select ... from tab1 where id=2 for update.

事务T2 lock tab1 .... write。

若无意向锁,事务T2需扫描表的每一行,看下是否有锁。

有了意向锁后,T2只需判断与T1的意向锁是否兼容即可。

 

2. Gap锁

Gap locks in InnoDB are purely inhibitive”, which means that their only purpose is to prevent other transactions from inserting to the gap. Gap locks can co-exist. A gap lock taken by one transaction does not prevent another transaction from taking a gap lock on the same gap. There is no difference between shared and exclusive gap locks. They do not conflict with each other, and they perform the same function.

 

3. Next-Key Locks

是Gap锁 与 Record Locks的结合,区间为前开后闭。如一个index 有10, 11, 13, and 20几条记录,则可能存在的Next-Key Locks是:

(negative infinity, 10]

(10, 11]

(11, 13]

(13, 20]

(20, positive infinity)

Next-Key Locks用于RR事务隔离级别,解决幻读问题。

 

mysql locking

标签:enc   5.7   ODB   form   sql   func   dex   fun   date   

原文地址:https://www.cnblogs.com/gm-201705/p/10057580.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!