- Dirty reads: read UNCOMMITED data from another transaction
- Non-repeatable reads: read COMMITTED data from an
UPDATE
query from another transaction
- Phantom reads: read COMMITTED data from an
INSERT
or DELETE
query from another transaction
Note : DELETE statements from another transaction, also have a very low probability of causing Non-repeatable reads in certain cases. It happens when the DELETE statement unfortunately, removes the very same row which your current transaction was querying. But this is a rare case, and far more unlikely to occur in a database which have millions of rows in each table. Tables containing transaction data usually have high data volume in any production environment.
Also we may observe that UPDATES may be a more frequent job in most use cases rather than actual INSERT or DELETES (in such cases, danger of non-repeatable reads remain only - phantom reads are not possible in those cases). This is why UPDATES are treated differently from INSERT-DELETE and the resulting anomaly is also named differently.
There is also an additional processing cost associated with handling for INSERT-DELETEs, rather than just handling the UPDATES.
- READ_UNCOMMITTED prevents nothing. It's the zero
isolation level
- READ_COMMITTED prevents just one, i.e. Dirty reads
- REPEATABLE_READ prevents two anomalies: Dirty reads and
Non-repeatable reads
- SERIALIZABLE prevents all three anomalies: Dirty reads,
Non-repeatable reads and Phantom reads
Then why not just set the transaction SERIALIZABLE at all times? Well, the answer to the above question is: SERIALIZABLE setting makes transactions very slow, which we again don't want.
In fact transaction time consumption is in the following rate:
SERIALIZABLE > REPEATABLE_READ > READ_COMMITTED > READ_UNCOMMITTED
So READ_UNCOMMITTED setting is the fastest.
Summary
Actually we need to analyze the use case and decide an isolation level so that we optimize the transaction time and also prevent most anomalies.
Note that databases by default may have REPEATABLE_READ setting. Admins and architects may have an affinity towards choosing this setting as default, to exhibit better performance of the platform.