Integrity Problems
Although locks can introduce contention and performance degradation, locks are still required to prevent the following integrity problems:
- Dirty reads
This type of read occurs when a database allows a transaction to read data that has been changed by another transaction but not yet committed. The changes made by the transaction may be rolled back, so the data read may turn out to be incorrect. Many databases allow dirty reads in order to avoid the contention caused by read locks.
- Nonrepeatable reads
This type of read occurs as a result of changes made by another transaction. A transaction performs a query based on a particular condition. After the data has been sent to this transaction, but before this transaction is complete, another transaction changes the data so that some of the previously retrieved data would no longer satisfy the selection condition. If the query were to be repeated in the same transaction, it would return a different set of results, so any changes made on the basis of the original results may no longer be valid. Data that was read once may return different results if it is read again later in the same transaction.
- Phantom reads
This type of read also occurs as a result of changes made by another transaction. One transaction performs a query based on a particular condition. After the data has been sent to this transaction, but before this transaction is complete, another transaction inserts new rows into the database that would have been selected ...