并发事务更新数据后读取数据的示例

以下示例说明了不同隔离级别在并发事务之后读取数据,以相同的隔离级别运行,更新一些行。

在该示例中,诺福德支持的所有三个隔离级别被示出。主事务的隔离级别与第二个,第三和第四列中的事务的隔离级别相同。换句话说:

  • The isolation_level for the main transaction is CONSISTENT READ when compared with the behavior of the statements listed in the CONSISTENT READ column.

  • The isolation_level for the main transaction is READ COMMITTED when compared with the behavior of the statements listed in the READ COMMITTED column.

死锁检测:如果存在阻止,则可能有可能的僵局。因此,Nuodb具有分布式死锁检测系统,可检测这些死锁,然后选择牺牲的交易之一(Force中止)。这与使用两阶段锁定的数据库都非常相似。

CONSISTENT READ

Shows how snapshot isolation prevents other transactions from seeing inserts and updates, even after the commit, unlike READ COMMITTED, where the other transactions could see the changes after the commit. CONSISTENT READ uses a snapshot view of the database as of the start of the transaction. This data remains consistent throughout the transaction.

READ COMMITTED

Allows all the other transactions to see its changes only after it has committed the changes. The important thing here is that neither inserts nor updates are visible to the other transactions until after the 犯罪. To do otherwise would have been, at least, an atomicity violation.

主要交易 CONSISTENT READ Transaction READ COMMITTED Transaction
CREATE TABLE t1 (f1 INTEGER);
 INTO t1 VALUES (1),(3),(5);
犯罪;
START TRANSACTION
ISOLATION LEVEL isolation_level;
选择 * FROM t1;
F1
---
1
3
5
START TRANSACTION
ISOLATION LEVEL SERIALIZABLE;
选择 * FROM t1;
F1
---
1
3
5
START TRANSACTION
ISOLATION LEVEL READ COMMITTED;
选择 * FROM t1;
F1
---
1
3
5
 INTO t1 VALUES(2);
选择 * FROM t1;
F1
---
1
3
5
2
选择 * FROM t1;
F1
---
1
3
5
选择 * FROM t1;
F1
---
1
3
5
更新 t1  f1=10 WHERE f1=1;
选择 * FROM t1;
F1
---
10
3
5
2
选择 * FROM t1;
F1
---
1
3
5
选择 * FROM t1;
F1
---
1
3
5
犯罪;
选择 * FROM t1;
F1
---
1
3
5
选择 * FROM t1;
F1
---
10
3
5
2