Choosing an isolation level — Aptitude Question
Choosing an isolation level: Which isolation level prevents dirty reads but still permits non-repeatable reads? Answer and worked solution on CodeKairo.
- Topic: OS, DBMS & Networks
- Section: Programming MCQs
- Difficulty: Medium
- Time target: 90 seconds
Question
Which isolation level prevents dirty reads but still permits non-repeatable reads?
Options
- Read Uncommitted
- Read Committed
- Repeatable Read
- Serializable
Show the answer and the worked solution
Correct answer: B. Read Committed
Worked solution
- Read Uncommitted lets a transaction see rows another transaction has not committed, which is precisely a dirty read.
- Read Committed reads only committed rows, so dirty reads disappear; but a row read twice may differ if another transaction commits an update in between, which is a non-repeatable read.
- Repeatable Read stops that as well, and Serializable additionally stops phantom rows.
Answer: Read Committed.
The idea
The four levels form a ladder against three anomalies: dirty read, non-repeatable read and phantom. Naming the anomaly the question describes points straight at the level.
Shortcut. The name says it: Read Committed reads only committed data, so no dirty reads, but holds no read locks to the end, so a re-read can change.
Common trap. "Repeatable Read" also prevents dirty reads, but it prevents non-repeatable reads too, which the question says must still be allowed.