gpt4 book ai didi

mysql - LOCK IN SHARE MODE 是否与 COUNT 一起使用

转载 作者:行者123 更新时间:2023-11-29 06:29:42 24 4
gpt4 key购买 nike

SELECT COUNT(*) FROM parent WHERE NAME = 'Jones' LOCK IN SHARE MODE;

锁定行的方法与

相同
SELECT * FROM parent WHERE NAME = 'Jones' LOCK IN SHARE MODE;

最佳答案

锁定共享模式的文档指定:

SELECT ... LOCK IN SHARE MODE sets a shared mode lock on any rows that are read. Other sessions can read the rows, but cannot modify them until your transaction commits. If any of these rows were changed by another transaction that has not yet committed, your query waits until that transaction ends and then uses the latest values.

这将基于事务读取的行。这两个查询通常会读取相同的行。

但是,如果 parent(name) 上有索引,则查询不等价。 count(*) 查询只需使用索引即可解决此问题,而 select * 则需要读取数据页。我假设 MySQL 会在仅索引查询期间锁定底层行,但我不是 100% 确定。

关于mysql - LOCK IN SHARE MODE 是否与 COUNT 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28658924/

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