I understand database transactions from illusory reading
At the beginning of the database transaction, there will always be dirty read, unrepeatable read, unreal read, read uncommitted, read committed, repeatable read and so on. Only to memorize a database transaction level, and each level can solve the problem, and the transaction level of different database implementation, until completely finished innodb engine’s handling of the transaction, in order to be thoroughly these transactions, the relationship between the when others asked again, can immediately according to the principle of the underlying clear relationship with the theory.
This article uses the InnoDB engine as an example to illustrate that other databases or engines are not well known.
A transaction is a set of operations that either all succeed or all fail. ACID (atomic, consistent, isolated, durable) is the property of a transaction.
The SQL standard defines four isolation levels:
- Read-uncommitted: The lowest isolation level that allows UNCOMMITTED data changes to be READ, potentially resulting in dirty, illusory, or unrepeatable reads.
- Read-committed: Allows concurrent transactions to READ data that has been COMMITTED, preventing dirty reads, but magic or unrepeatable reads can still occur.
- REPEATABLE-READ: Multiple reads of the same field are consistent, unless the data is modified by the transaction itself. This can prevent dirty reads and unrepeatable reads, but phantom reads are still possible.
- SERIALIZABLE: Highest isolation level, fully subject to ACID isolation level. All transactions are executed one by one so that interference between transactions is completely impossible. That is, this level prevents dirty reads, unrepeatable reads, and phantom reads.
And here’s a deceptively simple but confusing chart
Isolation level | Dirty read | Unrepeatable read | Phantom read |
---|---|---|---|
READ-UNCOMMITTED | Square root | Square root | Square root |
READ-COMMITTED | x | Square root | Square root |
REPEATABLE-READ | x | x | Square root |
SERIALIZABLE | x | x | x |