当前位置:网站首页>MySQL MVCC 多版本并发控制
MySQL MVCC 多版本并发控制
2022-06-10 21:47:00 【Li_XiaoJin】
关于多版本并发控制的一些内容。 主要来自于《高性能MySQL》,做笔记。
MCVV 的实现, 是通过保存数据在某个时间点的快照来实现的。 不管执行时间多长,每个事务看到的数据都是一致的。根据事务开始的时间不同,每个事务对同一张表,同一时刻看到的数据可能不一致。
主要介绍 InnoDB 的 MVCC 实现。
InnoDB 的 MVCC 是通过在每行记录后面保存两个隐藏的列来实现的。这两个列,一个保存了行的创建时间,一个保存了行的过期时间(或者删除时间)。存储的实际不是时间,可以看做是系统版本号。
每次开启一个事务时,系统版本号会进行递增。事务开始时刻的系统版本号会作为事务的版本号,用来和查询到的每行记录进行比较。
在 REPEATABLE READ 隔离级别下,MCCC 操作如下:
- SELECT InnoDB 会根据两个条件检查每行记录:
- InnoDB 只查找早于当前事务版本的数据行,这样确保了事务读取的行,要么是开始前已存在的,要么是事务自身插入或修改的。
- 行的删除版本要么未定义,要么大于当前事务,可以确保事务读取到的行,在事务开始之前删除。
只有符合以上两个条件才会进行返回查询的结果。
- INSERT InnoDB 为新插入的每一行保存当前系统版本号作为行版本号。
- DELETE InnoDB 为删除的每一行保存当前系统版本号作为行的删除标识。
- UPDATE InnoDB 为插入一行新记录,保存当前版本号作为行的行版本号,同时保存当前系统版本号到原赖的行作为行删除标识。
保存这两个版本号的优缺点
优点:
- 可以使得大多数读操作可以不用加锁
- 可以使得数据操作变得简单,性能好,保证了只会读取到符合标准的行
缺点:
- 每行都需要额外的存储空间
- 需要做更多行检查操作
- 需要做一些额外的维护工作
MVCC 只在 REPEATABLE READ 和 READ COMMITED 这两个隔离级别下工作,其他两个隔离级别不兼容,READ UNCOMMITED 每次只读取最新的数据行,而不是符合当前事务版本的数据行,SERIALIZABLE 则会对所有读取的行进行加锁。
Copyright: 采用 知识共享署名4.0 国际许可协议进行许可 Links:https://lixj.fun/archives/mvcc多版本并发控制
边栏推荐
- smb匿名
- That's great. The Ministry of industry and information technology has launched an internet account with a "one click unbinding" mobile phone number, which can be called an artifact
- Opencv_ 100 questions_ Chapter III (11-15)
- IP反查域名
- Watlow signs agreement to acquire EUROTHERM from Schneider Electric
- Reading notes on the way of Huawei data
- Whale conference empowers intelligent epidemic prevention
- [tcapulusdb knowledge base] tcapulusdb tcapproxy capacity expansion introduction
- kubernetes多网卡方案之Multus CNI部署和基本使用
- Storage engine analysis
猜你喜欢

Swin_ Interpretation of transformer source code
![[applet] vant sliding cell adds the function of clicking other positions to close automatically](/img/ef/3d954323a981026e2b917428cbc92b.png)
[applet] vant sliding cell adds the function of clicking other positions to close automatically

MySQL master-slave replication solves read-write separation
![[tcapulusdb knowledge base] tcapulusdb transaction management introduction](/img/cd/dc23cb8bddcbf04efeaf60dfadaec9.png)
[tcapulusdb knowledge base] tcapulusdb transaction management introduction

Play electronics, poor three generations

Whale conference empowers intelligent epidemic prevention

dc_labs--lab1的学习与总结
![[tcapulusdb knowledge base] tcapulusdb daily inspection introduction](/img/7b/8c4f1549054ee8c0184495d9e8e378.png)
[tcapulusdb knowledge base] tcapulusdb daily inspection introduction

Blue Bridge Cup_ A fool sends a letter_ recursion

dc_ Study and summary of labs--lab1
随机推荐
PKI/TLS瑞士军刀之cfssl
同花顺开户怎么样?开户安全吗?
[py] the failure of interface signature verification may be due to ensure_ ASCII problems
Keras深度学习实战(8)——使用数据增强提高神经网络性能
Can Huawei matepad become the secondary screen of your laptop?
Image mosaic camera mosaic notes
Basic use of mathtype7.x
Tcapulusdb Jun · industry news collection (IV)
[tcapulusdb knowledge base] tcapulusdb daily inspection introduction
Web3 ecological decentralized financial platform sealem Finance
mathtype7.x的基本使用
Custom view: graphics and image processing (I): using simple pictures
Face recognition software based on deepface model
What should I do if the mobile phone number cannot be updated
[tcapulusdb knowledge base] tcapulusdb tcapdb capacity expansion and contraction introduction
[tcapulusdb knowledge base] tcapulusdb tcapdb capacity expansion and contraction introduction
Watlow签订从施耐德电气手中收购Eurotherm的协议
Static routing configuration of serial interface in router experiment (Supplement)
vulnhub之dc3
[tcapulusdb knowledge base] tcapulusdb refresh tbus channel introduction