Files
Hui-s-notebook/logseq-java/pages/MVCC.md
2024-02-02 00:12:49 +08:00

24 lines
918 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
- 多版本并发控制
- 为了解决脏读,不可重复读的情况
- 基于Undo版本链接和ReadView来实现的每个事务都有自己的版本号
- MVCC无法解决幻读需要配合锁来实现
- 当前读
- select for update
- select lock in share mode
- insert update delete
- 快照读
- 维护了同一个行的多个版本,查询时会返回对应的事务的修改版本
- 原理
- 隐藏字段
- 行记录trx_id,roll_point
- undo版本链,由当前最新记录+该记录之间的undo日志
- readview
- 决定返回哪个版本的数据,版本链返回规则/可见性算法
- 当前活跃事务id
- 最大事务id +1
- 最小事务id
- readview创建者事务id
- RC和RR下
- RC每一次快照读都会生产readview
- RR只有第一次快照读生成readview后面复用
- MVCC解决了读写阻塞再RR下快照读方面避免了出现幻读的问题