当前位置:网站首页>Mvcc multi version control
Mvcc multi version control
2022-06-09 05:55:00 【I am a man in the middle of the mountain】
brief introduction
MVCC Version control is a kind of MySQL Mechanisms for implementing isolation levels , Leverage version chain 、undo journal 、readView Can solve dirty reading 、 Unrepeatable read problem ,MySQL The default isolation level is repeatable (REPEARABLE READ), It solves the problem that dirty reading cannot be re read , Unreal reading requires a gap lock + The solution of row lock , This article does not discuss .
MySQL Isolation level
MySQL The default isolation level is repeatable read (Repeatable Read)
MVCC
undo Log
undo log Official documents
undo log Is a log used to undo fallback , Before the transaction is committed ,MySQL The data before the update will be limited to undo log In the log file , When a transaction is rolled back, you can use undo log Back off . The right side of the figure below is a undo log Version chain , We'll talk about the specific explanation later .
Explain one of them roll_ptr and trx_id, Let's take a look at the official explanation first :

namely :
trx_id : Transaction fields , When a transaction operates on a row of data , Will put their own affairs Id Assign a value to trx_id Field
roll_ptr : rollback pointer , When a transaction updates a field , The previous fields will not be deleted directly , Instead, store the pointer to the previous field in undo blog
ReadView
MVCC among , Version number comparison is done by comparing transactions id, adopt ReadView Such a data structure , The data structure is as follows
m_ids: Currently active transactions ID list , Of all transactions in the transaction linked list id aggregate
min_trx_id: The first thing to start , The SQL Startup time , The smallest transaction in the current transaction list id Number , That is, the oldest transaction created in the current system but not yet committed
max_trx_id: The last transaction to start , The SQL Startup time , The largest transaction in the current transaction linked list id Number , That is, the maximum transaction number created recently except for itself
creator_trx_id: Means to generate the ReadView The business of id.
1. If the accessed version of trx_id Property value and ReadView Medium creator_trx_id Same value , It means that the current transaction is accessing its own modified records , So this version can be accessed by the current transaction .
2. If the accessed version of trx_id Attribute value less than ReadView Medium min_trx_id value , Indicates that the transaction generating this version generates ReadView Submitted before , So this version can be accessed by the current transaction .
3. If the accessed version of trx_id Property value is greater than or equal to ReadView Medium max_trx_id value , Indicates that the transaction generating this version generates ReadView It's only opened after , So this version cannot be accessed by the current transaction .
4. If the accessed version of trx_id The attribute value is ReadView Of min_trx_id and max_trx_id Between , Then we need to judge trx_id Is the attribute value in m_ids In the list , If in , Description creation ReadView The transaction that generated this version is still active , This version is not accessible ; If not , Description creation ReadView The transaction that generated this version has been committed , This version can be accessed .
If a version of the data is not visible to the current transaction , Then follow the version chain to find the data of the next version , Continue to follow the steps above to determine visibility , And so on , Until the last version in the version chain . If the last version is not visible , This means that the record is completely invisible to the transaction , The query result does not contain the record .
for instance :
There is a select sentence , Let's not mention its previous operation , Suppose it's trx_id by 110,select Time generation ReadView, here m_ids Among them are 100 and 120,min_trx_id by 100,max_trx_id by 120,min<110<max, So the fourth rule is true ,trx_id 100 and trx_id 120 Are invisible to them , You can only follow the version chain , Finally find the previous trx_id Not active id(m_ids) In the middle of “ initial ” The data of .
stay MySQL in ,READ COMMITTED and REPEATABLE READ A very big difference in isolation levels is that they generate ReadView The timing is different .
READ COMMITTED —— Generate a... Before each read ReadView
Because one is generated every time readview, So it may lead to the first select m_ids Wait for the data to be different from the following , Can not solve the problem of repeatable reading .
REPEATABLE READ —— Generate a... When reading data for the first time ReadView
边栏推荐
- debian11安装nfs server后固定端口号以便设置防火墙
- Wamp environment setup (apache+mysql+php)
- In latex, \cdots is followed by a sentence. What's wrong with the format of the following sentence.
- Synchronized detailed parsing
- Esmascript 6.0 advanced
- Dynamic data source
- 【论文】CBAM: Convolutional Block Attention Module
- vscode 出现TypeScript intellisense is disabled on template.错误
- Add failed when BigDecimal is 0.00
- SSL证书安装后网站还是显示不安全
猜你喜欢

Gstreamer应用开发实战指南(一)

Detailed understanding and learning of transactions in MySQL (transaction management, transaction isolation level, transaction propagation mechanism)

MVCC多版本控制

Topic26——11. 盛最多水的容器

Yolov5-6.0系列 | yolov5的模型网络构建

Analysis of the most complete webrtc server technology selection in history

WAMP环境搭建(apache+mysql+php)

三大队列cxq,entrylist,waitset 个人理解分析

Heqibao's trip to Chongqing ~

DBeaver导出查询数据sql文件
随机推荐
Swift protocol
微信小程序wx.getLocation定位错误信息汇总
XML建模
冒泡排序,打印菱形,打印直角三角形,打印倒三角,打印等边三角形,打印九九乘法表
Practical guide to GStreamer application development (III)
Leetcode 1037.有效的回旋镖
DBeaver导出查询数据sql文件
Ecmascript6.0 Basics
Local redis cluster setup
Gradient accumulation setting for pytorch DDP acceleration
Seaweedfs client adapts to the higher version of seaweedfs service
Fastdfs client tool class
杭州某家小公司一面
Yolov5-6.0系列 | yolov5的模型网络构建
Mysql5.7 one master multi slave configuration
Record rsyslog lost logs
Thread interrupted detailed parsing
1433:【例题1】愤怒的牛
Swift 协议
Esmascript 6.0 advanced