当前位置:网站首页>How to realize the four isolation levels of MySQL (brief)
How to realize the four isolation levels of MySQL (brief)
2022-07-01 11:07:00 【Rookie cat meow meow】
The four properties of a transaction
Namely Atomicity 、 Uniformity 、 Isolation, 、 persistence .
Atomicity :undolog Log to ensure , It records the log information that needs to be rolled back , When the transaction is rolled back, undo the executed sql.
Uniformity : It is guaranteed by three other features
Isolation, :MVCC To guarantee , Multi version concurrency control
persistence : from redolog To guarantee ,mysql When modifying data, it will be in redolog Record a log data in , Even if the data is not saved successfully , As long as the log is saved successfully , Data is still not lost .MySQL Collapse recovery hero —Redo Log
Concurrency of transactions
Dirty reading : Business A Transaction read B Data not submitted in , When a transaction B After rollback , Business A The data read is dirty .
It can't be read repeatedly : Business A Read the same data multiple times , But the value read each time is different . It's because of the business B Update and submit the data many times .
Fantasy reading : Business A During operation , Table data has been added or deleted many times , And the newly added or deleted data affects the transaction A The result of the operation .
Non repeatable reading focuses on data modification , Unreal reading focuses on adding or deleting data . Solve the problem of non repeatable reading , Only lock it , And solve unreal reading , You need to lock the whole table .
mysql Isolation level
The isolation level for database transactions is 4 individual , From low to high
Read uncommitted( Read uncommitted ): Dirty reading 、 It can't be read repeatedly 、 Fantasy reading All exist .
Read committed( Read submitted ): Solved the problem of dirty reading , There is Non repeatability 、 The problem of unreal reading .
Repeatable read( Repeatable ): Solved dirty reading 、 Unrepeatable read problem , There is Fantasy reading .
Serializable( Serialization ): Resolve all , But the concurrency efficiency is the lowest .
Implementation of isolation level
Read uncommitted (RU:read-uncommitted): You will read the data that has not been submitted .
When the isolation level is uncommitted read RU when :
- be-all Read without lock , The data read are the latest data , Best performance .
- All the writing Add line lock , After writing, release .
Read submitted (RC:read-committed): Use MVCC technology , Add hidden fields to each line (DB_TRX_ID: Modify the last transaction of the row id,DB_ROLL_PTR: Point to the current line undo log journal ,DB_ROW_ID: Line identification ,DELETE_BIT: Delete logo ), It realizes the read operation without lock .
When isolation level is RC when :
Write operations : Add line lock . When the business begins , Will be in UNDO Write the modification record in the log , Hidden columns in data rows DATA_POLL_PTR Store the UNDO Pointer to record .
Read operations : No locks . When reading , If the row is locked by other transactions , Then follow the hidden column DATA_POLL_PTR The pointer , Find the last valid history ( Effective records : This record is visible to the current transaction , And DELETE_BIT=0).
Repeatable (RR:repeatable-read): Use MVCC Technology to realize the read operation without lock .
- Write operations : Add line lock . When the business begins , Will be in UNDO Write the modification record in the log , Hidden columns in data rows DATA_POLL_PTR Store the UNDO Pointer to record .
- Read operations : No locks . When reading , If the row is locked by other transactions , Then follow the hidden column DATA_POLL_PTR The pointer , Find the last valid history ( Effective records : This record is visible to the current transaction , And DELETE_BIT=0).
Serialization (serializable): Read and write are locked .
You can see from above : actually Read submitted and Repeatable The operation of level is basically the same , The difference is : Row records for the current transaction visibility ( visibility : That is, which version of the row record is visible to this transaction ). The visibility of read submitted level to data is The latest record of this data , The visibility of repeatable basic data is At the beginning of the business , Record of this data .
边栏推荐
- Export and import of incluxdb on WIN platform
- Global filter (processing time format)
- Huawei Equipment configure les services de base du réseau WLAN à grande échelle
- The idea runs with an error command line is too long Shorten command line for...
- TEMPEST HDMI泄漏接收 3
- 12 plateformes de gestion de produits utilisées par tout le monde
- 力扣(LeetCode)181. 超过经理收入的员工(2022.06.29)
- 田溯宁投的天润云上市:市值22亿港元 年利润下降75%
- Spam filtering challenges
- Database experiment report (I)
猜你喜欢

How does MySQL copy table data from one database to another (two databases are not linked to the same database)

BAIC bluevale: performance under pressure, extremely difficult period

Exposure:A White-Box Photo Post-Processing Framework阅读札记

数据库实验报告(一)

Mobile hard drive reads but does not display drive letter

Infinite innovation in cloud "vision" | the 2022 Alibaba cloud live summit was officially launched

全局过滤器(处理时间格式)

The exclusive collection of China lunar exploration project is limited to sale!

2022年6月编程语言排行,第一名居然是它?!

谷歌新论文-Minerva:用语言模型解决定量推理问题
随机推荐
Crawler (2) - requests (1) | deep parsing of requests module
Can I choose to open an account on CICC securities? Is it safe?
MIT最新论文《对可解释特征的需求:动机和分类》:在机器学习模型的组成元素中建立可解释性
全局过滤器(处理时间格式)
关于Keil编译程序出现“File has been changed outside the editor,reload?”的解决方法
When is testing not unit testing- When is a Test not a Unit-test?
Value 1000 graduation project campus information publishing platform website source code
力扣(LeetCode)181. 超过经理收入的员工(2022.06.29)
Packet mode and three streaming modes in SDP protocol
The idea runs with an error command line is too long Shorten command line for...
Export and import of incluxdb on WIN platform
MIT's latest paper, "the need for interpretable features: motivation and classification": building interpretability in the constituent elements of machine learning models
Can servers bundled with flask be safely used in production- Is the server bundled with Flask safe to use in production?
想请教一下,我在广州,到哪里开户比较好?现在网上开户安全么?
Harbor webhook从原理到构建
CVPR 2022 | Virtual Correspondence: Humans as a Cue for Extreme-View Geometry
Network security learning notes 01 network security foundation
China's cellular Internet of things users have reached 1.59 billion, and are expected to surpass mobile phone users within this year
Combination of Oracle and JSON
金融壹账通拟7月4日香港上市:2年亏近30亿 市值蒸发超90%