当前位置:网站首页>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多版本并发控制
边栏推荐
- Déploiement et utilisation de base de la carte multi - réseau kubernets
- Shell basic concepts
- Vscode common shortcuts
- Auto.js pro 开发环境配置
- CCF CSP 202109-2 non zero segment division [100 points]
- Matlab - Implementation of evolutionary game theory
- Web3 ecological decentralized financial platform sealem Finance
- [tcapulusdb knowledge base] Introduction to tcapulusdb process startup
- [tcapulusdb knowledge base] tcapulusdb daily inspection introduction
- Simulated 100 questions and simulated examination of G2 utility boiler stoker examination in 2022
猜你喜欢

Several reasons and solutions of virtual machine Ping failure

ICML2022 | 从零开始重新审视端到端的语音到文本翻译
![[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

How to run Plink software -- three methods

MySQL主从复制解决读写分离

Missing heritability

vulnhub之dc4

leetcode 130. Surrounded regions (medium)

Bottom layer communication protocol ① of single chip microcomputer -- synchronous and asynchronous, parallel and serial, full duplex and half duplex, simplex, level signal and differential signal

"Draw the bow as strong, use the arrow as long", Manfu technology opens a new track for the data service industry
随机推荐
CCF CSP 202109-2 non zero segment division [100 points]
Whale conference sharing: what should we do if the conference is difficult?
LuoYongHao: if I were the person in charge, I could make apple products go up more than three steps
2022 t elevator repair test question simulation test question bank and online simulation test
分布式基础
CCF CSP 202109-4 收集卡牌
SMB anonymous
Watlow签订从施耐德电气手中收购Eurotherm的协议
[tcapulusdb knowledge base] tcapulusdb machine initialization and launch introduction
Vulnhub练习 DC-1靶机
vulnhub之DC2
SMB anonyme
QT custom delegation
[tcapulusdb knowledge base] tcapulusdb tcapdb capacity expansion and contraction introduction
[tcapulusdb knowledge base] tcapulusdb refresh tbus channel introduction
Multus CNI deployment and basic use of kubernetes multi network card scheme
Opencv_ 100 questions_ Chapter II (6-10)
Blue Bridge Cup_ Pick substring_ Combinatorial mathematics_ Multiplication principle/ Ruler method
Tcapulusdb Jun · industry news collection (VI)
IPO can't cure Weima's complications?