MySQL 加锁处理分析,何登成的,屌的一批
http://hedengcheng.com/?p=771#_Toc374698322
http://hedengcheng.com/?p=844
为什么开发人员必须要了解数据库锁?
https://mp.weixin.qq.com/s/7mGhEa-mHlRvC7fevwZ7pQ
理解innodb的锁(record,gap,Next-Key lock)
https://blog.csdn.net/cug_jiang126com/article/details/50596729
MySQL锁详解
https://www.cnblogs.com/luyucheng/p/6297752.html
Mysql中那些锁机制之InnoDB
https://www.2cto.com/database/201508/429967.html
MySQL InnoDB锁机制之Gap Lock、Next-Key Lock、Record Lock解析
http://blog.sina.com.cn/s/blog_a1e9c7910102vnrj.html
mysql insert锁机制
https://blog.csdn.net/zhanghongzheng3213/article/details/53436240
14.5.1 InnoDB Locking
https://dev.mysql.com/doc/refman/5.7/en/innodb-locking.html
Locks Set by Different SQL Statements in InnoDB
https://dev.mysql.com/doc/refman/5.6/en/innodb-locks-set.html
InnoDB Lock and Lock-Wait Information
https://dev.mysql.com/doc/refman/5.7/en/innodb-information-schema-understanding-innodb-locking.html
INSERT ... ON DUPLICATE KEY UPDATE
冲突后更新数据,id不会变,但是会占用一次自增主键,下次插入数据时候自增主键看着是跳步的。
要点:
1、Gap locking is not needed for statements that lock rows using a unique index to search for a unique row.
即根据主键更新时候加gap lock。
2、gap lock,只是为了阻塞insert
死锁相关:
1、如何阅读死锁日志
http://blog.itpub.net/22664653/viewspace-2145133/
2、一次Mysql死锁排查过程的全纪录
https://m.jb51.net/article/106247.htm
3、
如果是单纯的record lock,显示的是:locks rec but not gap
如果是单纯的gap lock, 显示的是:locks gap before rec
如果是gap+record,也就是next key lock,显示的是:lock_mode X <空>
InnoDB 事务锁系统简介
http://mysql.taobao.org/monthly/2016/01/01/
一致性读、锁定读
https://dev.mysql.com/doc/refman/5.6/en/innodb-consistent-read.html
https://dev.mysql.com/doc/refman/5.6/en/innodb-locking-reads.html
mvcc相关:
1、关于innodb中MVCC的一些理解
http://www.cnblogs.com/chenpingzhao/p/5065316.html
https://blog.csdn.net/chen77716/article/details/6742128
2、思路:
一致性读(Consistent Nonlocking Reads)-> InnoDB is a multi-versioned storage engine -> undo log -> undo log中的行就是MVCC中的多版本 ->
不可重复读的重点是修改 :
同样的条件 , 你读取过的数据 , 再次读取出来发现值不一样了
幻读的重点在于新增或者删除
同样的条件 , 第 1 次和第 2 次读出来的记录数不一样
IS NULL Optimization
MySQL can perform the same optimization on col_name IS NULL that it can use for col_name = constant_value. For example, MySQL can use indexes and ranges to search for NULL with IS NULL.
https://dev.mysql.com/doc/refman/5.7/en/is-null-optimization.html