# Transaction Isolation Levels
# Comparision
Isolation Level | Dirty reads | Non-repeatable reads | Phantoms | Read | Write |
---|---|---|---|---|---|
Serializable | Impossible | Impossible | Impossible | Shared Lock | Exclusive Lock |
Repeatable Read | Impossible | Impossible | Probaly | MVCC (data at begin of tx) | Exclusive Lock |
Read Committed | Impossible | Probaly | Probaly | MVCC (latest committed data tx) | Exclusive Lock |
Read Uncommitted | Probaly | Probaly | Probaly | No Lock | Exclusive Lock |
Dirty reads occur when:
- Transaction A inserts a row into a table.
- Transaction B reads the new row.
- Transaction A rolls back.
Nonrepeatable reads occur when:
- Transaction A reads a row.
- Transaction B changes the row.
- Transaction A reads the same row a second time and gets the new results.
Phantom reads occur when:
- Transaction A reads all rows that satisfy a WHERE clause on an SQL query.
- Transaction B inserts an additional row that satisfies the WHERE clause.
- Transaction A re-evaluates the WHERE condition and picks up the additional row.
# Explicit / Exclusive Locking
- Table-Level Locks
- Row-Level Locks
- Page-Level Locks
- Advisory Locks