当前位置:网站首页>MySQL isolation level
MySQL isolation level
2022-04-23 07:41:00 【cqwoniu】
One 、 Four characteristics of transactions
The isolation level of the transaction is ACID, That is atomicity 、 Uniformity 、 Isolation, 、 persistence .
1、 Atomicity
Atomicity means that the operation of the whole transaction is either committed successfully , Either all failures roll back .
2、 Uniformity
Consistency means that the database always changes from one consistent state to another consistent state , If the transaction is not committed , The changes made will not be saved to the database .
3、 Isolation,
Changes made by a transaction are made before the final submission , Is invisible to other transactions .
4、 persistence
Once the transaction is committed , The changes made will be permanently saved to the database .
Realized ACID The database of , Usually stronger cpu Processing power and more memory and more disk space .
Two 、 If there is no isolation , What will happen ?
1、 Dirty reading
Business A | Business B |
---|---|
Open transaction A | |
Open transaction B | |
The query balance is 100 | |
Increase balance to 150 | |
The query balance is 150 |
Why is it dirty reading , Because no submission , If you roll back , Then the data read at this time is just a mirage .
2、 It can't be read repeatedly
Business A | Business B |
---|---|
Open transaction A | |
Open transaction B | |
The query balance is 100 | |
Increase balance to 150 | |
The query balance is 100 | |
Commit transaction | |
The query balance is 150 |
Refers to a transaction scope , Query a data multiple times , But got different results .
Between two reads in the first transaction , Due to the modification of the second transaction , The data read by the first transaction twice may be different .
3、 Fantasy reading
Business A | Business B |
---|---|
Open transaction A | |
Open transaction B | |
Inquire about id<3 The records of 3 strip | |
Add a id=2 The record of | |
Commit transaction | |
Inquire about id<3 There are four records |
Another example is business T1 A data item is removed from all rows in a table “1” It is amended as follows “2” The operation of , When the transaction T2 Another row of data item is inserted into this table, which is “1” The data of , And submit it to the database . And operating transactions T1 If the user views the data that has just been modified , Will you find the data or 1, Actually this row is from the transaction T2 Added in , It's like hallucinating , This is where the phantom reading occurs .
Unreal reading and non repeatable reading are both read and submitted data , But unreal reading is aimed at a batch of data , Non repeatable reading is for a row of data .
3、 ... and 、 The isolation level of the transaction
1、 Uncommitted read
Changes in transactions , Even if it's not submitted , It's also visible to other things , Transactions can read uncommitted data , Uncommitted reading cannot avoid any of the above problems .
2、 Read submitted
When a transaction begins , You can only see the changes made by the submitted firm . Avoid dirty reading .
3、 Repeatable
In the same business , The result of multiple reads is the same . It can avoid dirty reading and repeatable reading , But unreal reading cannot be avoided .
4、 Serialization
Is the highest isolation level , Force transactions to execute serially , Avoid unreal reading 、 It can't be read repeatedly 、 Dirty reading problem , The serial will lock each row of data , Therefore, it may cause a lot of timeout and lock contention problems . Only if the consistency of data is ensured and a large number of concurrency can be accepted , To consider using this level .
版权声明
本文为[cqwoniu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230622032004.html
边栏推荐
猜你喜欢
On BFC (block formatting context)
Lead the industry trend with intelligent production! American camera intelligent video production platform unveiled at 2021 world Ultra HD Video Industry Development Conference
‘npm‘不是内部或外部命令,也不是可运行的程序 或批处理文件
安装配置淘宝镜像npm(cnpm)
学习笔记5-梯度爆炸和梯度消失(K折交叉验证)
Solutions to common problems in visualization (VII) solutions to drawing scale setting
数据分析入门 | kaggle泰坦尼克任务(四)—>数据清洗及特征处理
vim+ctags+cscpope开发环境搭建指南
Background management system framework, there is always what you want
如何SQL 语句UNION实现当一个表中的一列内容为空时则取另一个表的另一列
随机推荐
对STL容器的理解
反思 | 事件总线的局限性,组件化开发流程中通信机制的设计与实现
Date对象(js内置对象)
配置npm
刨根问底---cocos2d源码的理解与分析
The difference and application of VR, AR and MR, as well as some implementation principles of AR technology
数论分块(整除分块)
判断字符串首尾是否包含目标参数:startsWith()、endsWith()方法
(扩展)BSGS与高次同余方程
两个线程交互打印奇偶数字
P1446 [HNOI2008]Cards(Burnside定理+dp计数)
3.排序语句
Design optimization of MySQL database
直观理解熵
如何SQL 语句UNION实现当一个表中的一列内容为空时则取另一个表的另一列
Background management system framework, there is always what you want
Nacos/sentinel网关限流和分组 (代码)
[CF 1425D]Danger of Mad Snakes(组合计数+容斥)
VIM使用
[hdu6868]Absolute Math(推式子+莫比乌斯反演)