当前位置:网站首页>Database dirty reads, non-repeatable reads, phantom reads and corresponding isolation levels
Database dirty reads, non-repeatable reads, phantom reads and corresponding isolation levels
2022-07-30 10:36:00 【Little Zhang Free -> Zhang Youbo】
目录
Problems with concurrent reading of data
幻读:Multiple reads were made within a transaction,数据总量不一致
不可重复读:A transaction reads the same data,The data content before and after is inconsistent
读未提交:All read problems can occur,This isolation level is generally not taken
读已提交:Only dirty reads can be avoided,Oracle默认的隔离级别
可重复读:能够避免脏读、不可重复读,MySQL中Innodb引擎默认的隔离级别
Problems and solutions that occur under concurrent transactions
Problems with concurrent reading of data
脏读:一个事务读取另一个事务未提交的数据
A事务读取B事务尚未提交的数据,此时如果B事务发生错误并执行回滚操作,那么A事务读取到的数据就是脏数据.就好像原本的数据比较干净、纯粹,此时由于B事务更改了它,这个数据变得不再纯粹.这个时候A事务立即读取了这个脏数据,但事务B良心发现,又用回滚把数据恢复成原来干净、纯粹的样子,而事务A却什么都不知道,最终结果就是事务A读取了此次的脏数据,称为脏读.
幻读:Multiple reads were made within a transaction,数据总量不一致
事务A在执行读取操作,需要两次统计数据的总量,前一次查询数据总量后,此时事务B执行了新增数据的操作并提交后,这个时候事务A读取的数据总量和之前统计的不一样,就像产生了幻觉一样,平白无故的多了几条数据,成为幻读.
不可重复读:A transaction reads the same data,The data content before and after is inconsistent
事务A在执行读取操作,由整个事务A比较大,前后读取同一条数据需要经历很长的时间 .而在事务A第一次读取数据,比如此时读取了小明的年龄为20岁,事务B执行更改操作,将小明的年龄更改为30岁,此时事务A第二次读取到小明的年龄时,发现其年龄是30岁,和之前的数据不一样了,也就是数据不重复了,系统不可以读取到重复的数据,成为不可重复读.
can be understood as based on the sameId查询,The results are inconsistent
区别:
1.Dirty read refers to a transaction read其他事务未提交的数据.
2.Non-repeatable read means that the same piece of data is read multiple times in a transaction and has changed,The focus is on the tableExisting data has been modified by other transactions.
3.A phantom read is when a transaction is affected by data inserted or deleted by other transactions,The point is after the transaction has started,Other transactions inserted or deleted data.
脏读、幻读、Non-repeatable reads only happen in the case of concurrent transactions,为了解决这些问题,Databases introduce isolation levels,And different isolation levels can solve different problems.
隔离级别
读未提交:All read problems can occur,This isolation level is generally not taken
在这种隔离级别下,所有事务能够读取其他事务未提交的数据.读取其他事务未提交的数据,会造成脏读.因此在该种隔离级别下,不能解决脏读、不可重复读和幻读.
读已提交:Only dirty reads can be avoided,Oracle默认的隔离级别
在这种隔离级别下,所有事务只能读取其他事务已经提交的内容.能够彻底解决脏读的现象.但在这种隔离级别下,会出现一个事务的前后多次的查询中却返回了不同内容的数据的现象,也就是出现了不可重复读.
可重复读:能够避免脏读、不可重复读,MySQL中Innodb引擎默认的隔离级别
在这种隔离级别下,所有事务前后多次的读取到的数据内容是不变的.也就是某个事务在执行的过程中,不允许其他事务进行update操作,但允许其他事务进行add操作,造成某个事务前后多次读取到的数据总量不一致的现象,从而产生幻读.
可串行化:All read problems can be solved,But since it is executed serially,Performance efficiency is relatively low
在这种隔离级别下,所有的事务顺序执行,所以他们之间不存在冲突,从而能有效地解决脏读、不可重复读和幻读的现象.但是安全和效率不能兼得,这样事务隔离级别,会导致大量的操作超时和锁竞争,从而大大降低数据库的性能,一般不使用这样事务隔离级别.
Problems and solutions that occur under concurrent transactions
| 隔离级别 | 脏读 | 不可重复读 | 幻读 |
| 读未提交 | 可能(出现) | 可能 | 可能 |
| degree submitted | 不可能(出现) | 可能 | 可能 |
| 可重复读 | 不可能 | 不可能 | 可能 |
| 可串行化 | 不可能 | 不可能 | 不可能 |
如果本篇博客对您有一定的帮助,大家记得留言+点赞+收藏哦
边栏推荐
- Meikle Studio - see the actual combat notes of Hongmeng device development 4 - kernel development
- 死锁的理解
- MySQL | Subqueries
- 105. 从前序与中序遍历序列构造二叉树(视频讲解!!)
- flowable工作流所有业务概念
- 【AGC】增长服务2-应用内消息示例
- In the robot industry professionals, Mr Robot industry current situation?
- New in GNOME: Warn users when Secure Boot is disabled
- BERT预训练模型系列总结
- 4、yolov5-6.0 ERROR: AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘ 解决方案
猜你喜欢

Nacos configuration in the project of battle

论文阅读:SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers

Re20:读论文的先例:普通法的信息理论分析

图像去噪——Neighbor2Neighbor: Self-Supervised Denoising from Single Noisy Images

Verilog之数码管译码

新一代开源免费的终端工具,太酷了

MFCC to audio, the effect should not be too funny >V

jmeter接口压力测试-(二)

PyQt5 - draw sine curve with pixels

通过构建一个顺序表——教你计算时间复杂度和空间复杂度(含递归)
随机推荐
【 HMS core 】 【 】 the FAQ HMS Toolkit collection of typical questions 1
唯物辩证法-条件论
BERT预训练模型系列总结
OC - Manual Reference Counting Memory Management
OC-手动引用计数内存管理
你真的懂Redis的5种基本数据结构吗?
A new generation of free open source terminal tool, so cool
jmeter接口压力测试(一)
4. yolov5-6.0 ERROR: AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor' solution
Re20:读论文 What About the Precedent: An Information-Theoretic Analysis of Common Law
Materialist Dialectics - Conditionalism
Flink_CDC搭建及简单使用
Container Technology - A Simple Understanding of Kubernetes Objects
spark udf 接受并处理 null值.
Practical Walkthrough | Calculate Daily Average Date or Time Interval in MySQL
Meikle Studio-Look at the actual combat notes of Hongmeng device development six-wireless networking development
Detailed explanation of JVM memory layout, class loading mechanism and garbage collection mechanism
Re21:读论文 MSJudge Legal Judgment Prediction with Multi-Stage Case Representation Learning in the Real
时刻铭记:总有一天你将破蛹而出
MySQL installation tutorial [installation version]