当前位置:网站首页>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 | 不可能(出现) | 可能 | 可能 |
| 可重复读 | 不可能 | 不可能 | 可能 |
| 可串行化 | 不可能 | 不可能 | 不可能 |
如果本篇博客对您有一定的帮助,大家记得留言+点赞+收藏哦
边栏推荐
- Container Technology - A Simple Understanding of Kubernetes Objects
- 【HMS core】【Analytics Kit】【FAQ】如何解决华为分析付费分析中付款金额显示为0的问题?
- paging
- 系统设计精选 | 基于FPGA的CAN总线控制器的设计(附代码)
- mysql安装教程【安装版】
- JCL learning
- Meikle Studio-Look at the actual combat notes of Hongmeng device development six-wireless networking development
- Matplotlib--plot markers
- CVTE school recruitment written test questions + summary of knowledge points
- Redis Desktop Manager 2022.4.2 发布
猜你喜欢

nacos实战项目中的配置

Flask's routing (app.route) detailed

线上靶机prompt.ml

Flask之路由(app.route)详解

第1章 Kali与靶机系统

【HMS core】【FAQ】HMS Toolkit Typical Questions Collection 1

(***Key points***) Flink common memory problems and tuning guide (1)

(文字)无框按钮设置

(C language) file operation

Detailed explanation of JVM memory layout, class loading mechanism and garbage collection mechanism
随机推荐
数据库脏读、不可重复读、幻读以及对应的隔离级别
flowable workflow all business concepts
Study Notes 10--Main Methods of Local Trajectory Generation
Scrapy爬虫之网站图片爬取
CVTE school recruitment written test questions + summary of knowledge points
GNOME 新功能:安全启动被禁用时警告用户
Practical Walkthrough | Calculate Daily Average Date or Time Interval in MySQL
ospf2 two-point two-way republish (question 2)
梅科尔工作室-看鸿蒙设备开发实战笔记五——驱动子系统开发
北京突然宣布,元宇宙重大消息
Meikle Studio-Look at Hongmeng Device Development Practical Notes 7-Network Application Development
A near-perfect Unity full-platform hot update solution
新一代开源免费的终端工具,太酷了
Multi-threading scheme to ensure that a single thread opens a transaction and takes effect
WARN: Establishing SSL connection without server's identity verification is not recommended when connecting to mysql
阿里云OSS对象存储
软考 系统架构设计师 简明教程 | 案例分析 | 需求分析
105. Construct binary tree from preorder and inorder traversal sequence (video explanation!!)
Linux内核设计与实现(十)| 页高速缓存和页回写
自适应控制——仿真实验一 用李雅普诺夫稳定性理论设计自适应规律