gpt4 book ai didi

mysql - 为什么MySQL innodb使用next-key锁而不是记录锁?

转载 作者:行者123 更新时间:2023-11-29 23:13:30 25 4
gpt4 key购买 nike

MySQL innodb's document据说在默认的事务隔离级别“repeatable-read”下,MySQL在处理“update”和“delete”语句时会发出next-key锁。

我很困惑为什么它不会使用记录锁而不是下一个键锁,因为下一个键锁的优点是它可以避免“幻读”,但它在隔离级别“可重复读”中是允许的。

最佳答案

从您链接的页面

InnoDB does not remember the exact WHERE condition, but only knows which index ranges were scanned. The locks are normally next-key locks that also block inserts into the “gap” immediately before the record.

因此,下一个键锁也会阻止对选定范围的插入,而记录锁则不会。

关于mysql - 为什么MySQL innodb使用next-key锁而不是记录锁?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27967628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com