1、默认情况下,innodb使用临键锁锁定记录。文章源自飞鸟学习网-https://www.pk88.net/2022-0301-16.html
select...forupdate
2、当查询索引包含唯一属性时,临键锁将被优化并降级为记录锁,即只锁定索引本身,而不是范围。文章源自飞鸟学习网-https://www.pk88.net/2022-0301-16.html
3、不同场景下的临键锁会退化。文章源自飞鸟学习网-https://www.pk88.net/2022-0301-16.html
实例文章源自飞鸟学习网-https://www.pk88.net/2022-0301-16.html
事务1 starttransaction; selectSLEEP(4); select*fromtestwhereage=22forupdate; select*fromtestwhereage>23forupdate; selectsleep(20); commit; ************************** 事务2 starttransaction; selectsleep(8); select*fromtestwhereage=20forupdate; select*fromtestwhereage=21forupdate; select*fromtestwhereage=22forupdate; select*fromtestwhereage=23forupdate; commit; ************************************ 事务执行状态 事务1 starttransaction >OK >时间:0s selectSLEEP(4) >OK >时间:4.001s select*fromtestwhereage=22forupdate >Affectedrows:0 >时间:0.001s select*fromtestwhereage>23forupdate >Affectedrows:0 >时间:0.001s selectsleep(20) >OK >时间:20s commit >OK >时间:0.001s *********************** 事务2 starttransaction >OK >时间:0.001s selectsleep(8) >OK >时间:8s select*fromtestwhereage=20forupdate >Affectedrows:0 >时间:0.001s select*fromtestwhereage=21forupdate >Affectedrows:0 >时间:0.001s select*fromtestwhereage=22forupdate >Affectedrows:0 >时间:14.158s select*fromtestwhereage=23forupdate >Affectedrows:0 >时间:0.001s commit >OK >时间:0s
以上就是mysql临键锁的使用,希望对大家有所帮助。文章源自飞鸟学习网-https://www.pk88.net/2022-0301-16.html
文章源自飞鸟学习网-https://www.pk88.net/2022-0301-16.html
继续阅读
全站资源源于网络整合,仅供学习研究,不可商用,不提供技术指导,如有侵权请告知删除,可以投稿,广告合作联系V: pk88net

我的微信
微信扫一扫
评论