gpt4 book ai didi

mysql - 为什么锁定读取忽略隔离级别?

转载 作者:行者123 更新时间:2023-12-04 03:33:30 25 4
gpt4 key购买 nike

例子:

SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
START TRANSACTION;
SELECT * FROM t1; // to "create shapshot". For simplicity t1 contains 1 row 1 column which contains value 1.
// another transaction updates this row and change 1 to 2 and commits.
SELECT * FROM t1; // we see no changes. As expected in repeatable read.
SELECT * FROM t1 FOR UPDATE; // i see change row. Why?

我找不到对这种行为的解释的问题。为什么锁定读取忽略隔离级别?

最佳答案

https://dev.mysql.com/doc/refman/8.0/en/innodb-locking-reads.html说:

SELECT ... FOR UPDATE

For index records the search encounters, locks the rows and any associated index entries, the same as if you issued an UPDATE statement for those rows. Other transactions are blocked from updating those rows, from doing SELECT ... FOR SHARE, or from reading the data in certain transaction isolation levels. Consistent reads ignore any locks set on the records that exist in the read view. (Old versions of a record cannot be locked; they are reconstructed by applying undo logs on an in-memory copy of the record.)

换句话说,锁定读取只能锁定行的最新提交版本。

关于mysql - 为什么锁定读取忽略隔离级别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67393916/

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