gpt4 book ai didi

mysql - 选择共享模式锁定

转载 作者:IT老高 更新时间:2023-10-28 23:52:28 24 4
gpt4 key购买 nike

我已阅读this article from dev.mysql .

在该页面中有一个示例,当使用选择进行更新并且不在共享模式下使用锁定并说

Here, LOCK IN SHARE MODE is not a good solution because if two users read the counter at the same time, at least one of them ends up in deadlock when it attempts to update the counter

但是这个页面的第一行说

SELECT ... LOCK IN SHARE MODE: The rows read are the latest available, ** so if they belong to another transaction ** that has not yet committed, the read blocks until that transaction ends.

是否存在悖论?

我的意思是两个用户不会同时读取计数器因为如果它们属于另一个事务,则读取 阻塞直到该事务结束。

最佳答案

如果有另一个事务修改了该行,则 SELECT ... LOCK IN SHARE MODE 等待。如果该行没有被修改,它不会等待。这导致了第一种情况,即2个事务可以SELECT ... LOCK IN SHARE MODE,但它们都不能更新记录(死锁)

关于mysql - 选择共享模式锁定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6607006/

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