Isolation

Isolation imposes rules, which ensure that transactions do not interfere with each other even if they are executed at the same time. If 2 (or more) transactions are executed at the same time, they must be executed in a way so that transaction N won't be impacted by the intermediate data of transaction M. Note, that isolation does not dictate the order of the transactions. Another important thing to understand about isolation is serializability of transactions. If the effect on the database is the same when transactions are executed concurrently or when their execution is interleaved, these transactions are called serializable.

There are several degrees of isolation to be distinguished:

The more common classification is by isolation levels:

  1. Serializable
  2. In this case, transactions are executed serially so that there is no concurrent data access. Transactions can also be executed concurrently but only when the illusion of serial transactions is maintained (i.e. no concurrent access to data occurs).  If the system uses locks, a lock should be obtained over the whole range of selected data ("WHERE" clause in SQL). If the system does not use locks, no lock is acquired; however, if the system detects a concurrent transaction in progress, which would violate the serializability illusion, it must force that transaction to rollback, and the application will have to restart the transaction.

  3. Repeatable Read
  4. In this case, a lock is acquired over all the data retrieved from a database. Phantom reads can occur (i.e. new data from the other committed transactions included in the result)

  5. Read Committed
  6. In this case, read locks are acquired on the result set, but released immediately. Write locks are acquired and released only at the end of the transaction. Non-repeatable reads can occur, i.e. deletions or modifications from the other committed transactions will be visible by the current transaction. Phantom reads are also possible.

  7. Read Uncommitted
  8. With this isolation level dirty reads are allowed.  Uncommitted modifications from the other transactions are visible. Both phantom and nonrepeatable reads can occur.