当前位置:网站首页>MySQL transaction isolation level and mvcc
MySQL transaction isolation level and mvcc
2022-06-13 10:37:00 【edui】
MVCC English full name Multi-Version Concurrency Control, Translation into Chinese means Multi version concurrency control . Achieve non blocking concurrent access . The principle is similar 《Java Inside CAS Realization principle 》 Who is like who? Maybe we can learn by analogy
- Transaction isolation level
Dirty write : One transaction modifies the modified data of another uncommitted transaction , That is to say, when the area modifies the uncommitted part of others, the modification will no longer exist when rolling back .
Dirty reading : One transaction reads data modified by another uncommitted transaction , During the same rollback, a non-existent data is read ,
It can't be read repeatedly : That is to say, when a transaction is not committed, another data is read , After reading, the data is modified by another transaction , When the uncommitted transaction reads the data again, it is different from the previous one . This leads to non repeatable reading , The values read multiple times in the same transaction are different .
Fantasy reading : Similar to nonrepeatable reading , However, the number of records read twice is different , Suddenly appear like a phantom .
SQL The standard isolation levels are as follows :
Isolation level | name | Dirty reading | It can't be read repeatedly | Fantasy reading |
---|---|---|---|---|
READ UNCOMMITTED | Uncommitted read | Possible | Possible | Possible |
READ COMMITTED | Read committed | Not Possible | Possible | Possible |
REPEATABLE READ | Repeatable | Not Possible | Not Possible | Possible |
SERIALIZABLE | Serializable | Not Possible | Not Possible | Not Possible |
There is no dirty writing because , Dirty writes are not allowed at all isolation levels .
- MySQL Isolation level
Different databases support standards SQL The isolation level of is different ,MySQL All four isolation levels support , And MySQL The default isolation level for is REPEATABLE READ, We can manually modify the isolation level of transactions . and MySQL stay REPEATABLE READ Under isolation level , It can prohibit the occurrence of unreal reading problems .
1、 Use READ UNCOMMITTED Isolation level transactions , Because you can read the modified records of uncommitted transactions , So just read the latest version of the record
2、 For the use of SERIALIZABLE For isolation level transactions , The designer specifies to access the records by locking
3、 For the use of READ COMMITTED and REPEATABLE READ For isolation level transactions , You must ensure that you read the transaction modified records that have been committed , That is, if another transaction has modified the record but has not yet committed , You can't read the latest version of the record directly , The core issue is : You need to determine which version in the version chain is visible to the current transaction , - readview
readview Save the currently active read / write transactions ID、 The smallest transaction currently active ID、 The next transaction to be generated ID( Predict by the global variable that generated the transaction )、 Generate this readview The business of ID. With this readview, When you want to access a record, first judge that there is a transaction in the hidden column of the record ID, That is, modify the transaction of the record ID, If less than and not active readview Active list in , It indicates that the transaction has been committed and can be accessed directly , If it is still in the active list, it means that it is still active and can not be read. Otherwise, it will Dirty reading . If it is greater than, it means that readview The transactions generated after are inaccessible, or they will occur Can't read repeatedly or unreasonably . When it is inaccessible, the rollback pointer in the hidden column will be obtained to find undo The logs are then compared until they are accessible or until the end of the version chain .《 What is the version chain 》 - RC and RR Different implementations of isolation levels
READ COMMITTED —— Generate a... Before each read ReadView
That is, if there are multiple read operations in the transaction , Each read generates a ReadView snapshot , That is to say, the last time it was read ReadView It may not be the same as this reading , So you may read a different version, that is Can't read repeatedly or unreasonably
REPEATABLE READ —— Generate a... When reading data for the first time ReadView
That is, once the transaction starts , The first query is the same as several queries in the same transaction ReadView, That is, the version freeze frame snapshot starts the transaction , The version read every time in the future is the same , That is, it will not happen Can't read repeatedly or unreasonably
Dirty reading is impossible , Because both reads are unreadable in the transaction active version , That is, only the version of the committed transaction can be read . So it's impossible to dirty read .
The principle is similar 《Java Inside CAS Realization principle 》 Who is like who? Maybe we can learn by analogy
- reflection
Will find MVCC Good! , No jam , But the discovery only solves the problem of reading , Writing cannot guarantee , How to avoid dirty writing , Of course, it comes by way of a lock , Before modifying a record, lock it and do not modify other transactions, that is, dirty writes will not occur . There's another problem , What to do when a business needs to read the latest value every time MVCC What you read may be an old version , Of course, this requirement is also solved by locking the read and write . There is also the understanding that one is , There is no lock in the normal query tone , Unless you explicitly write lock , A lock will be added in the writing tone without other statements to ensure that dirty locks will not occur ,,,, Details of the lock
Transferred to 《MySQL—— Brief description of locking mechanism 》
边栏推荐
- 技术管理进阶——管理者可以使用哪些管理工具
- 检验冗余码是否出错题型解法-摘录
- Some experience in database table structure design
- deepin系统中Qt5.12无法输入中文(无法切换中文输入法)解决办法
- 网传互联网公司加班表,排名第一的没有悬念!
- Cynthia项目缺陷管理系统
- ThingsBoard教程(二十):使用规则链过滤遥测数据
- 周末赠书:Power BI数据可视化实战
- The first laravel workflow engine released the official version of v1.0
- of_find_compatible_node查找出所有的节点
猜你喜欢
架构师必备:系统容量现状checklist
Vivo large scale kubernetes cluster automation operation and maintenance practice
记几次略有意思的 XSS 漏洞发现
中国SaaS产业全景图谱
How to optimize MySQL?
Install Kubernetes 1.24
【ELM分类】基于粒子群优化卷积神经网络CNN结合极限学习机ELM实现数据分类附matlab代码
苹果放大招!这件事干的太漂亮了……
Redundancy code question type -- the difference between adding 0 after
Blue Bridge Cup group 2021a - two way sorting
随机推荐
winform 解决黑屏 频繁刷新
Matlab hub motor analysis fuzzy PID control vertical vibration analysis
知识图谱入门
Questions and answers of the labor worker general basic (labor worker) work license in 2022
IDEA远程调试spark-submit提交的jar
Sunyuchen, head of Grenada delegation, attended the WTO MC12 and emphasized the development of digital economy
【云享新鲜】社区周刊·Vol.66-华为伙伴暨开发者大会2022精彩议程公布
Experience of electric competition - program-controlled wind pendulum
逐向双碳:东数西算中的绿色需求与竞争焦点
Node red series (27): instructions for S7 node of the extension node
等个有“源”人|OpenHarmony 成长计划学生挑战赛报名启动
Mysql database conceptual design using E-R model
Programming principles
Wait for someone with "source" | openharmony growth plan student challenge registration to start
D evaluate twice map
MySQL到底怎么优化?
JS local storage
Develop a basic module with low code
Docker部署Mysql
2022年劳务员-通用基础(劳务员)上岗证题目及答案