当前位置:网站首页>Detailed explanation of mvcc and its principle
Detailed explanation of mvcc and its principle
2022-07-27 05:00:00 【Meme_ xp】
What do you mean mvcc
Multi version concurrency control , If only one transaction or single thread operates on data .
In the current mainstream production environment, it is impossible for only one thread to operate on the database , At this time, it is necessary to ensure data consistency .
So what are the application scenarios in the case of concurrency ?
1. Read
There is no problem , There is no need to add any locks , There is no need for concurrency control
2. Write about
There may be the possibility of loss and renewal
3. Reading and writing
How to guarantee concurrent reading and writing ? Lock , But it's inefficient ————mvcc, It is to solve the problem of reading and writing data in the case of concurrency
Pre skills :
1. The current reading :
What is read is always the latest data recorded in the database
Which operations will cause the current read :
1.updata
2.insert
3.delete
4.select…for updata
5.select…lock in share mode
2. Read the snapshot :
What is read is not the latest data , But the data of a historical version
Those will cause snapshot reading : Save the essence select
Snapshot problem : If the database 100g Then I'll take pictures of them all ?
Each row of data can have multiple versions , Who modifies which transaction in each version modifies this transaction_id One by one .
So this 100g The snapshot of is not right 100g, Not copy and paste to form a snapshot , Instead, it reads row trxI_ID, The latest version number of the current transaction is read .
because transaction_id Is increasing in order , We put the submitted transactions ID The maximum value of is recorded as up_limit_id
After we start the transaction , We read the data , If I record more than up_limit_id We don't recognize !
What do you mean , Let me give you an example :

1 To 5 Execute in order , here Q1,Q2 What's the value of ?

Why? b yes 20 No 19??

It says updata Trigger current read , So I read the latest data

Let's continue to analyze step by step :
Suppose the last version number submitted in the database is 999
First step :
First, a Started the business , Then the b Open transaction , Then the c Open transaction , And all records up_limit_id=999( Maximum )

The second step
Business c Changed the age


The third step
Business b modify ,updata Trigger snapshot read , Directly modify the values at the database level , Get the latest data in the database

Get is 1002 Number , That's business c Version number of , Then modify the version number . The result is


Business b When reading data again , Because of the latest revision 1001 No. modified , So what I got was 1001, Just match yourself , To recognize, so the age is 20 year
Step four :


a The last version of the transaction record is 999.1001 If not, continue to look up ,1002 Still not in line with , Read 999, In line with , return . Show 18.
边栏推荐
- Explanation of index failure principle and its common situations
- [search] two way search + A*
- Interesting C language
- RN development series < 9 > --mobx (1) Introduction
- Error: cannot read properties of undefined (reading 'then')
- 【报错】:Cannot read properties of undefined (reading ‘prototype‘)
- Plato Farm有望通过Elephant Swap,进一步向外拓展生态
- Final Cut Pro中文教程 (1) 基础认识Final Cut Pro
- 单元测试chapter6
- 打开编程的大门
猜你喜欢

IIC communication protocol (I)
![[construction of independent stations] this website is the first choice for cross-border e-commerce companies to open online stores at sea!](/img/26/22597a7ece0431a4e54703945a775c.jpg)
[construction of independent stations] this website is the first choice for cross-border e-commerce companies to open online stores at sea!

Find a specific number in an ordered array

2019强网杯upload

TCP three handshakes and four disconnects

MySQL下载安装 & 完美卸载

js小技巧

Grid layout

Photoshop裁剪工具隐藏技巧

Vscode opens a new chapter in the visualization of pull request update code branches
随机推荐
不需手动安装cuda和cudnn,通过一行程序即可安装tensorflow-gpu,以tensorflow-gpu2.0.0,cuda10.0,cudnn7.6.5为例
安装Pygame
Solution: how to use bash batch command in win10
小程序项目如何创建
STL 上头系列——list 容器详解
接口和抽象类/方法学习 demo
C language address book management system (linked list, segmented storage of mobile phone numbers, TXT file access, complete source code)
IP 14th day notes
[C language] detailed explanation of user-defined types (structure + enumeration + Union)
HCIA dynamic routing OSPF experiment
Safety fourth after class exercise
.htaccess learning
Final Cut Pro Chinese tutorial (1) basic understanding of Final Cut Pro
How do I reset Photoshop preferences? PS method of resetting preferences
How to import PS style? Photoshop style import tutorial
数字中国建设峰会闭幕,现场海量图片一览!
CDH cluster integration external Flink (improved version - keep pace with the times)
Photoshop裁剪工具隐藏技巧
Structural mode - decorator mode
Reproduce ssa-gan using the nine day deep learning platform