参考链接:ISOLATION LEVELS
ISOLATION LEVELS
In a database system, concurrent transactions are processed in “isolation” from each other. The level of isolation determines how transactions can affect each other.
UNDERSTANDING ISOLATION LEVELS
READ-UNCOMMITTED
Here transactions can see changes to data made by other transactions that are not yet committed.
In other words, transactions can read data that eventually may not exist, given that other transactions can always rollback the changes without commit. This is known as a dirty read. Effectively,
READ-UNCOMMITTED
has no real isolation at all.
- 事务A可以读取到事务B还未 commit的数据
- 若事务B回滚数据,则事务A将产生
脏读
READ-COMMITTED
Here dirty reads are not possible. Uncommitted changes remain invisible to other transactions until the transaction commits.
However, at this isolation level
SELECT
queries use their own snapshots of committed data, that is data committed before the
SELECT
query executed. As a result,
SELECT
queries, when run multiple times within the same transaction, can return different result sets. This is called a non-repeatable read.
- 事务A不可以读取到事务B还未 commit的数据,即:未commit的数据,对其他事务不可见;
- 不会产生
脏读
- 同一事务的多次select查询,使用的数据快照可能不同,因此查询结果可能不同,即:
;不可重复读
REPEATABLE-READ
Here non-repeatable reads are not possible. Snapshots taken for the
SELECT
query are taken the first time the
SELECT
query runs during the transaction.
- 不会产生
和脏读
问题不可重复读
- 同一事务的多次select查询,使用的数据快照相同,都使用第一次select时的数据快照,而不管其他是否有没有commit更新;
SERIALIZABLE
- 不会产生幻影读(不确定)