当前位置:网站首页>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 | 不可能(出现) | 可能 | 可能 |
可重复读 | 不可能 | 不可能 | 可能 |
可串行化 | 不可能 | 不可能 | 不可能 |
如果本篇博客对您有一定的帮助,大家记得留言+点赞+收藏哦
边栏推荐
- paging
- what is this method called
- Verilog之数码管译码
- js对数组操作移动进行封装
- Re17: Read the paper Challenges for Information Extraction from Dialogue in Criminal Law
- Nacos configuration in the project of battle
- (C language) file operation
- Redis Desktop Manager 2022.4.2 发布
- Array of Shell System Learning
- [100个Solidity使用技巧]1、合约重入攻击
猜你喜欢
再有人问你分布式事务,把这篇扔给他
EViews 12.0 software installation package download and installation tutorial
多线程--线程和线程池的用法
New in GNOME: Warn users when Secure Boot is disabled
Adaptive Control - Simulation Experiment 1 Designing Adaptive Laws Using Lyapunov's Stability Theory
Re16:读论文 ILDC for CJPE: Indian Legal Documents Corpus for Court Judgment Prediction and Explanation
Security思想项目总结
[AGC] Growth Service 2 - In-App Message Example
Meikle Studio - see the actual combat notes of Hongmeng equipment development five - drive subsystem development
【HMS core】【Analytics Kit】【FAQ】如何解决华为分析付费分析中付款金额显示为0的问题?
随机推荐
flowable workflow all business concepts
图像去噪——Neighbor2Neighbor: Self-Supervised Denoising from Single Noisy Images
论文阅读:SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers
Nacos configuration in the project of battle
SST-Calib:结合语义和VO进行时空同步校准的lidar-visual外参标定方法(ITSC 2022)
Baidu promotion assistant encounters duplicate keywords, verification errors, how to delete redundant ones with one click
Re18:读论文 GCI Everything Has a Cause: Leveraging Causal Inference in Legal Text Analysis
spark udf accepts and handles null values.
Flink_CDC搭建及简单使用
606. Create a string from a binary tree (video explanation!!!)
[AGC] Growth Service 2 - In-App Message Example
Meikle Studio-Look at the actual combat notes of Hongmeng device development six-wireless networking development
Mysterious APT Attack
(C语言)文件操作
软考 系统架构设计师 简明教程 | 案例分析 | 需求分析
(BUG record) No module named PIL
在机器人行业的专业人士眼里,机器人行业目前的情况如何?
BERT pre-training model series summary
105. Construct binary tree from preorder and inorder traversal sequence (video explanation!!)
Day113. Shangyitong: WeChat login QR code, login callback interface