当前位置:网站首页>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.
边栏推荐
- JS day 2 (variables, variable usage, naming rules, syntax extensions)
- Why is select not recommended*
- HCIA static routing basic simulation experiment
- "Photoshop2021 tutorial" align and distribute to make dot patterns
- kali系统arp介绍(断网嗅探密码抓包)
- Comprehensive experiment of static routing
- What if Photoshop prompts that the temporary storage disk is full? How to solve the problem that PS temporary storage disk is full?
- MySQL下载安装 & 完美卸载
- 【搜索】双向广搜 + A*
- Open the door of programming
猜你喜欢

【搜索】—— 多源BFS + 最小步数模型

Comprehensive experiment of static routing

二叉搜索树详讲

OFDM 十六讲 2- OFDM and the DFT

Simple static routing in ENSP

Affine transformation module and conditional batch Standardization (CBN) of detailed text generated images

Plato farm is expected to further expand its ecosystem through elephant swap

CEPH operation

Knowledge about hash index and b+ tree

Reproduce ssa-gan using the nine day deep learning platform
随机推荐
如何将Photoshop图层复制到其他文档
STM32 cubeMX HAL-----PWM—改变频率
写代码涉及到的斜杠/和反斜杠\
5. Display of component dynamic components
利用Power Automate,轻松下载Power BI报告中的数据
C language address book management system (linked list, segmented storage of mobile phone numbers, TXT file access, complete source code)
Plato farm is expected to further expand its ecosystem through elephant swap
[construction of independent stations] this website is the first choice for cross-border e-commerce companies to open online stores at sea!
勤于奋聊聊现在还有哪些副业可以做
【Acwing】第61场周赛 题解
JS tips
Grid layout
Bo Yun container cloud and Devops platform won the trusted cloud "technology best practice Award"
2019强网杯upload
Bubble sort (detailed)
Solution to the third game of 2022 Hangzhou Electric Multi school league
STL 上头系列——list 容器详解
Idea 如何新建一个groovy的项目(图文详细解释)
双向重发布实验
The usage syntax and scene of selector, as well as the usage of background picture size, text box shadow and excessive effect