标题更正:脏读 -> 不可重复读。 这个问题说白了就是定义的问题,网上的答案不一,有人在刷题小程序里指正,但理由又不能让我信服。所以查了一些比较官方的定义,感觉也是比较混乱。

sql 1992 标准

http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt

2) P2 ("Non-repeatable read"): SQL-transaction T1 reads a row. SQL-

   transaction T2 then modifies or deletes that row and performs
   a COMMIT. If T1 then attempts to reread the row, it may receive
   the modified value or discover that the row has been deleted.


3) P3 ("Phantom"): SQL-transaction T1 reads the set of rows N
   that satisfy some. SQL-transaction T2 then
   executes SQL-statements that generate one or more rows that
   satisfy theused by SQL-transaction T1. If
   SQL-transaction T1 then repeats the initial read with the same
   , it obtains a different collection of rows.

不可重复读:事务 T1 读到某行;事务 T2 修改或删除这行,提交事务;T1 重新读取发现这行数据已经被修改或删除。

幻读:事务 T1 读取了 N 行;事务 T2 在事务 T1 读取的条件范围内生成了一行或多行数据;T1 重新读取获得与之前不同集合的行数据。


mysql 官网的术语解释,8.0 最新版

https://dev.mysql.com/doc/refman/8.0/en/glossary.html

non-repeatable read
The situation when a query retrieves data, and a later query within the same transaction retrieves what should be the same data, but the queries return different results (changed by another transaction committing in the meantime).


phantom
A row that appears in the result set of a query, but not in the result set of an earlier query. For example, if a query is run twice within a transaction, and in the meantime, another transaction commits after inserting a new row or updating a row so that it matches the WHERE clause of the query.

This occurrence is known as a phantom read. It is harder to guard against than a non-repeatable read, because locking all the rows from the first query result set does not prevent the changes that cause the phantom to appear.

不可重复读:一个事务内,两次相同条件的查询返回了不同的结果。

幻读:同一个事务中,一条数据出现在这次查询的结果集里,却没有出现在之前的查询结果集中。例如,在一个事务中进行了同一个查询运行了两次,期间被另外一个事务提交插入一行或修改查询条件匹配的一行。它比不可重复读更难防范,因为锁定第一个查询结果集的所有行并不能阻止导致幻象出现的更改。


从以上两处的定义可以看出


影响因素

sql 1992 标准mysql 术语解释
不可重复读
其他事务修改或删除
未明确不同结果的原因
幻读
新增一行或多行
新增或修改


so,不同出处的规定存在细微差别,并非完全统一。


ps:交流中进步,再次感谢每位指出错误的朋友!


更多相关文章

  1. MyBatis 如何编写一个自定义插件?运行原理是什么?
  2. 帆软报表自定义函数-取json数据
  3. mysql从入门到优化(3)事务的基本操作
  4. 分布式系统的事务处理
  5. 一文讲透微服务下如何保证事务的一致性

随机推荐

  1. Android(安卓)中clipToPadding 和 clipCh
  2. android 更换皮肤项目
  3. Android 修改默认的ProgressBar的动画效
  4. android ndk安装是使用
  5. Android maxLine属性导致android:imeOpti
  6. 【Android】SDK手动下载
  7. Android(安卓)OTA 升级之三:生成recovery.
  8. Android播放器框架分析之AwesomePlayer
  9. Android资源汇总---持续整理更新中!!!
  10. Android开发常用网站