当前位置:网站首页>MySQL transaction mvcc principle
MySQL transaction mvcc principle
2022-07-04 09:26:00 【Studious little Tao】
Let's discuss in Mysql RR and RC Under isolation level MVCC Multi version concurrency control , stay Mysql in MVCC The mechanism is to use undo log Version chain mechanism implementation ReadView Mechanism .
ReadView
ReadView What is it? , Simply speaking ,ReadView When starting a transaction , It will generate a ReadView Used to implement MVCC Mechanism . Here is ReadView Some key things contained in
- m_ids: This means at this time mysql Which transactions in the transaction have not been committed
- min_trx_id: Minimum business Id, Namely m_ids The smallest transaction in Id
- max_trx_id: The biggest business Id, Namely Mysql The next transaction to generate Id, Is the biggest thing Id
- creator_trx_id: Current affairs Id
stay Mysql There are two hidden fields behind each data row in ,trx_id and roll_pointer
- trx_id: Current data update transactions Id
- roll_pointer: Point to next undo log Version chain , Used to find undo log Data in the version chain
RC ISOLATION Realization principle
Read submitted : Transactions can only read committed data ; stay Mysql in , Each transaction query generates a new ReadView To achieve RC.
MVCC Realization RC Isolation level : Each query will generate a new Readview, Let's look at the following example
1、 Here is a piece of data in the database :
2、 If A The transaction queries the submitted data ,trx_id = 1, At this time, I will make a judgment , Just to judge trx_id Less than min_trx_id, So it proves that this data dates back to A The transaction has been committed before it starts , So you can query this data .
3、 If the transaction B(id = 25) Modified this line of data , And submitted , So this data is trx_id Will be changed to trx_id = 25, meanwhile roll_pointer Will point to trx_id = 10 That piece of data , as follows undo log Version chain . At this point, the transaction A Launch the query again , Will generate a new ReadView, So at this time trx_id stay min_trx_id and ma_trx_id Within limits , Not at the same time m_ids In the list , So it proves that this transaction change has been committed , stay RC It can be read under the isolation level .
4、 When a transaction A After modifying this data , The trx_id Changed to 20, here trx_id Although in m_ids In the list , At the same time, the current data trx_id The value of and ReadView in creator_id The value of is the same , This shows that this data is a transaction A Altered , So at this time A Transactions can be queried .
RR ISOLATION Realization principle
Repeatable : Business A Multiple queries , The result is the same ;Mysql By generating a fixed ReadView Realization RR Isolation level .
MVCC Realization RR Isolation level : Each query will be used when the transaction is opened ReadView, Let's look at the following example
1、 Here is a piece of data in the database :
2、 If the transaction A(id = 20) And is a matter B(id = 25) Open the transaction at the same time , Well, at this time ReadView yes :
3、 If the transaction A(id = 20) Open query , Find current data trx_id = 10, Less than min_trx_id, So it means that this data is in the transaction A Submitted before opening , So this data can be queried .
4、 If the transaction B(id = 25) Changed data , So at this point trx_id = 25, By looking at A Of ReadView You can see ,trx_id = 25 stay m_ids In the list , So it explains the transaction B And business A Is a transaction started at the same time , So in RR It cannot be queried under the isolation level .
5、 If the transaction A(id = 20) Changed this data again , So at this time trx_id = 20, By looking at A Of ReadView You can see ,trx_id = 20 stay m_ids In the list , however trx_id = 20 And A Of ReadView in creator_trx_id The value of is the same , So this data is A The transaction itself changes , So it can be queried .
6、 If there is a new transaction at this time C(id = 30) Changed this data , So at this time trx_id = 30, By inquiring ReadView You can see ,trx_id = 30 No longer m_ids In the list , however trx_id Greater than max_trx_id, So it means that this data is in A Started after the transaction is started , Therefore, it is impossible to query .
summary
The above mainly introduces MVCC Realization RR and RC Implementation of isolation level , Rookie learning summary , Bosses do not spray .
边栏推荐
- Clion console output Chinese garbled code
- Review of last week's hot spots (6.27-7.3)
- Dede plug-in (multi-function integration)
- Global and Chinese markets of thrombography hemostasis analyzer (TEG) 2022-2028: Research Report on technology, participants, trends, market size and share
- 【leetcode】540. A single element in an ordered array
- Awk from entry to earth (14) awk output redirection
- [on February 11, 2022, the latest and most fully available script library collection of the whole network, a total of 23]
- 《网络是怎么样连接的》读书笔记 - WEB服务端请求和响应(四)
- Tkinter Huarong Road 4x4 tutorial II
- 【leetcode】29. Divide two numbers
猜你喜欢

2022-2028 global intelligent interactive tablet industry research and trend analysis report

2022-2028 global industry research and trend analysis report on anterior segment and fundus OTC detectors

Sword finger offer 30 contains the stack of Min function

2022-2028 global tensile strain sensor industry research and trend analysis report

Explain TCP protocol in detail three handshakes and four waves
![[C Advanced] file operation (2)](/img/50/e3f09d7025c14ee6c633732aa73cbf.jpg)
[C Advanced] file operation (2)

Some points needing attention in PMP learning

After unplugging the network cable, does the original TCP connection still exist?

How to ensure the uniqueness of ID in distributed environment

HMS core helps baby bus show high-quality children's digital content to global developers
随机推荐
Report on research and investment prospect prediction of China's electronic grade sulfuric acid industry (2022 Edition)
[on February 11, 2022, the latest and most fully available script library collection of the whole network, a total of 23]
After unplugging the network cable, does the original TCP connection still exist?
《网络是怎么样连接的》读书笔记 - 集线器、路由器和路由器(三)
Global and Chinese market of sampler 2022-2028: Research Report on technology, participants, trends, market size and share
AMLOGIC gsensor debugging
Langage C - démarrer - base - syntaxe - [opérateur, conversion de type] (vi)
C語言-入門-基礎-語法-[運算符,類型轉換](六)
老掉牙的 synchronized 锁优化,一次给你讲清楚!
Les différents modèles imbriqués de listview et Pageview avec les conseils de flutter
Awk from entry to soil (5) simple condition matching
Mac platform forgets the root password of MySQL
2022-2028 global intelligent interactive tablet industry research and trend analysis report
In depth research and investment strategy report on China's hydraulic parts industry (2022 Edition)
2022-2028 global seeder industry research and trend analysis report
The map set type is stored in the form of key value pairs, and the iterative traversal is faster than the list set
Global and Chinese markets of water heaters in Saudi Arabia 2022-2028: Research Report on technology, participants, trends, market size and share
【leetcode】29. Divide two numbers
Latex download installation record
Global and Chinese markets of thrombography hemostasis analyzer (TEG) 2022-2028: Research Report on technology, participants, trends, market size and share