4. Overview
...
Anomalies
..
..
..
Isolation Levels
.
.....
FAQ
Brief
ACID properties of database system.
• Atomic
Each transaction is regarded as atomic.
• Consistency
The consistency property ensures that any transaction will
bring the database from one valid state to another.
• Isolation
Users should be able to understand a transaction without
considering the effect of other concurrently executing
transactions.
• Durability
Once the DBMS informs the user that a transaction has been
successfully completed, its effects should persist even if
the system crashes before all its changes are reflected on
disk.
4 / 31
5. Overview
...
Anomalies
..
..
..
Isolation Levels
.
.....
FAQ
Brief
Strict 2-Phase Locking1
.
Rule 1
.
• Shared lock Allow another transaction to read.
.
• Exclusive lock No allow another transaction to read or write.
.
Rule 2
.
All locks held by a transaction are released when the transaction is
completed.
.
1
Strict 2PL
5 / 31
6. Overview
...
Anomalies
..
..
..
Isolation Levels
.
.....
FAQ
Brief
About Isolation Level
• Most DBA System offers a number of transaction isolation
levels, which control the degree of locking when selecting
data.
• The higher isolation level, the more locks needed.
It is trade-off.
• For concurrency control, with multiple transactions.
6 / 31
12. Overview
...
Anomalies
..
..
..
Isolation Levels
.
.....
FAQ
Dirty Reads
Level/Anomaly
Read Uncommitted
Read Committed
Repeatable Read
Serializable
Level/Locks
Read Uncommitted
Read Committed
Repeatable Read
Serializable
Dirty Read
Maybe
No
No
No
Unrepetable read
Maybe
Maybe
No
No
Write Lock
X
X
X
Read Lock
S
X
X
Phantom
Maybe
Maybe
Maybe
No
Range Lock
X
12 / 31
13. Overview
...
Anomalies
..
..
..
Isolation Levels
.
.....
FAQ
Dirty Reads
Transaction 1
.
/∗ Query 1 ∗/
SELECT ag e FROM u s e r s WHERE i d =
1;
/∗ w i l l r e a d 20 ∗/
Transaction 2
.
/∗ Query 2 ∗/
UPDATE u s e r s SET age = 21 WHERE i d
= 1;
/∗ No commit h e r e ∗/
.
.
.
/∗ Query 1 ∗/
SELECT ag e FROM u s e r s WHERE i d =
1;
/∗ w i l l r e a d 21 ∗/
.
ROLLBACK ;
.
.
13 / 31
19. Overview
...
Anomalies
..
..
..
Isolation Levels
.
.....
FAQ
Phantoms
Transaction 1
.
/∗ Query 1 ∗/
SELECT ∗ FROM u s e r s
WHERE age BETWEEN 10 AND 3 0 ;
Transaction 2
.
/∗ Query 2 ∗/
INSERT INTO u s e r s ( i d , name , a g e )
VALUES ( 3 , ’ Bob ’ , 27 ) ;
COMMIT;
.
.
.
/∗ Query 1 ∗/
SELECT ∗ FROM u s e r s
WHERE age BETWEEN 10 AND 3 0 ;
.
19 / 31
26. Overview
...
Anomalies
..
..
..
Isolation Levels
.
.....
FAQ
Repeatable Reads and Serializable
• Obtains exclusive locks before reading or writing.
• All locks released until the end of transaction, according to
Strict 2-PL.
.
.
• Repeatable Reads → locks individual object.
• Serializable → locks set of objects.
26 / 31