mvcc中的read_view
发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,innodb的mvcc和read view最近读High Performance MySQL,里面提到了innodb事务隔离级别是REPEATABLE-READ时,有这样一段话引用SELECTInno
千家信息网最后更新 2025年11月07日mvcc中的read_viewinnodb的mvcc和read view
最近读High Performance MySQL,里面提到了innodb事务隔离级别是REPEATABLE-READ时,有这样一段话
引用
SELECT
InnoDB must examine each row to ensure that it meets two criteria:
a. InnoDB must find a version of the row that is at least as old as the transaction
(i.e., its version must be less than or equal to the transaction's version). This
ensures that either the row existed before the transaction began, or the trans-
action created or altered the row.
b. The row's deletion version must be undefined or greater than the transaction's
version. This ensures that the row wasn't deleted before the transaction began.
Rows that pass both tests may be returned as the query's result.
来验证一下
表中有数据(1,1)
autocommit为false, tx_isolation 是REPEATABLE-READ
考虑以下两种情况
情况1
B处结果为(1,2),似乎不符合那段话里的a条件,A事务看到了transaction version更大的B事务
情况2
C处结果为(1,1),也就是说,A事务没有看到transaction version更小的B事务
是不是那段话有问题呢,后来终于找到了官方的文档,innodb通过read view来确定一致性读时的数据库snapshot,innodb的read view确定一条记录能否看到,有两条法则
1 看不到read view创建时刻以后启动的事务
2 看不到read view创建时活跃的事务
引用 Rule 1: When the read view object is created it notes down the smallest transaction identifier that is not yet used as a transaction identifier (trx_sys_t::max_trx_id). The read view calls it the low limit. So the transaction using the read view must not see any transaction with identifier greater than or equal to this low limit.
Rule 2: The transaction using the read view must not see a transaction that was active when the read view was created.
在情况1中,代码A处并没有创建read view,read view是在代码B处创建的.
如果把A处代码改为 START TRANSACTION WITH CONSISTENT SNAPSHOT;
才会创建read view,使得代码B返回(1,1)
在情况2中,B事务在A事务创建read view时处于ACTIVE状态,所以B事务不会被A事务看到.
这篇文章还提到了mysql5.6 在read only事务的优化,值得一看
最近读High Performance MySQL,里面提到了innodb事务隔离级别是REPEATABLE-READ时,有这样一段话
引用
SELECT
InnoDB must examine each row to ensure that it meets two criteria:
a. InnoDB must find a version of the row that is at least as old as the transaction
(i.e., its version must be less than or equal to the transaction's version). This
ensures that either the row existed before the transaction began, or the trans-
action created or altered the row.
b. The row's deletion version must be undefined or greater than the transaction's
version. This ensures that the row wasn't deleted before the transaction began.
Rows that pass both tests may be returned as the query's result.
来验证一下
show create table 20130302t1; CREATE TABLE `20130302t1` ( `id` int(11) NOT NULL, `b` int(11) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB
表中有数据(1,1)
autocommit为false, tx_isolation 是REPEATABLE-READ
考虑以下两种情况
情况1
| session A | session B |
| start transaction;(A) | |
| start transaction | |
| update 20130302t1 set b=2 where id=1; | |
| commit; | |
| select * from 20130302t1;(B) |
B处结果为(1,2),似乎不符合那段话里的a条件,A事务看到了transaction version更大的B事务
情况2
| session A | session B |
| start transaction | |
| update 20130302t1 set b=2 where id=1; | |
| start transaction | |
| select * from 20130302t1; | |
| commit; | |
| select * from 20130302t1;(C) |
C处结果为(1,1),也就是说,A事务没有看到transaction version更小的B事务
是不是那段话有问题呢,后来终于找到了官方的文档,innodb通过read view来确定一致性读时的数据库snapshot,innodb的read view确定一条记录能否看到,有两条法则
1 看不到read view创建时刻以后启动的事务
2 看不到read view创建时活跃的事务
引用 Rule 1: When the read view object is created it notes down the smallest transaction identifier that is not yet used as a transaction identifier (trx_sys_t::max_trx_id). The read view calls it the low limit. So the transaction using the read view must not see any transaction with identifier greater than or equal to this low limit.
Rule 2: The transaction using the read view must not see a transaction that was active when the read view was created.
在情况1中,代码A处并没有创建read view,read view是在代码B处创建的.
如果把A处代码改为 START TRANSACTION WITH CONSISTENT SNAPSHOT;
才会创建read view,使得代码B返回(1,1)
在情况2中,B事务在A事务创建read view时处于ACTIVE状态,所以B事务不会被A事务看到.
这篇文章还提到了mysql5.6 在read only事务的优化,值得一看
事务
情况
代码
数据
结果
一致
一致性
也就是
也就是说
会创
官方
数据库
文档
时刻
是在
条件
法则
状态
篇文章
级别
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网络技术ui设计
数据库营销的过程
武汉市网络安全大赛
浙江fil服务器
郴州应用软件开发
网络安全介绍视频
南昌市服务器包装公司价格
比较火的网络技术
大话西游2龙的传人服务器怎么样
正规软件开发厂家
阿里云服务器和中国电信哪个好
名企c软件开发岗面试真题
数据库联机
软件开发标准的书籍
asp链接sql数据库
cn域名只能国内服务器吗
百万网络安全基地
互联网科技模板
软件开发 pr是什么
华为服务器光盘怎么打开
云服务器无法安装应用
华为v5服务器发布
复工服务企业网络安全
数据库大作业逻辑结构设计
洛奇数据库
云裳甄选公司网络技术员
qq分享屏幕显示服务器异常
jsp web服务器搭建
网络安全流量清洗设备
静安区电商软件开发诚信合作