脏读:一个事务读取另外一个事务还没有提交的数据。
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 术语解释 | |
不可重复读 | 其他事务修改或删除 | 未明确不同结果的原因 |
幻读 | 新增一行或多行 | 新增或修改 |
不同出处的规定存在细微差别,并非完全统一。