当前位置:网站首页>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 | 不可能(出现) | 可能 | 可能 |
| 可重复读 | 不可能 | 不可能 | 可能 |
| 可串行化 | 不可能 | 不可能 | 不可能 |
如果本篇博客对您有一定的帮助,大家记得留言+点赞+收藏哦
边栏推荐
- CVTE school recruitment written test questions + summary of knowledge points
- (C language) file operation
- WARN: Establishing SSL connection without server's identity verification is not recommended when connecting to mysql
- 【 HMS core 】 【 】 the FAQ HMS Toolkit collection of typical questions 1
- OC-ARC (Automatic Reference Counting) automatic reference counting
- 梅科尔工作室-看鸿蒙设备开发实战笔记七——网络应用开发
- Basemap和Seaborn
- Always remember: one day you will emerge from the chrysalis
- 线程池方式开启线程--submit()和execute()的区别
- STM32CubeMX configuration to generate FreeRTOS project
猜你喜欢

Re16: Read the paper ILDC for CJPE: Indian Legal Documents Corpus for Court Judgment Prediction and Explanation

电压跟随器不要随便加

Nacos configuration in the project of battle

mysql安装教程【安装版】

Detailed explanation of JVM memory layout, class loading mechanism and garbage collection mechanism

A new generation of free open source terminal tool, so cool

第2章 常用安全工具

Quick Start Tutorial for flyway

多线程保证单个线程开启事务并生效的方案

Re20:读论文 What About the Precedent: An Information-Theoretic Analysis of Common Law
随机推荐
Pytorch中 nn.Transformer的使用详解与Transformer的黑盒讲解
这种叫什么手法
【AGC】增长服务2-应用内消息示例
Soft Exam System Architect Concise Tutorial | Case Analysis | Requirement Analysis
Scrapy crawler website image crawling
【HMS core】【FAQ】HMS Toolkit Typical Questions Collection 1
A near-perfect Unity full-platform hot update solution
图像去噪——Neighbor2Neighbor: Self-Supervised Denoising from Single Noisy Images
2022年顶会accepted papers list
Redis Desktop Manager 2022.4.2 released
PyQt5 - Drawing different types of straight lines
Determine whether a tree is a complete binary tree - video explanation!!!
从数据流中快速查找中位数
Always remember: one day you will emerge from the chrysalis
新一代开源免费的终端工具,太酷了
Meikle Studio-Look at Hongmeng Device Development Practical Notes 7-Network Application Development
STM32CubeMX configuration to generate FreeRTOS project
Mysterious APT Attack
关于verilog的时延研究
(BUG record) No module named PIL