8. Transaction Processing

A logical unit of work consisting of one or more statements. The effects of the transaction only becomes permanent when the transaction is completed successfully.

An application program may contain several transactions.

The basic data operations are read and write. A read operation will:

A write operation will:

A transaction can be in the following states:

The transaction can be aborted when in the active or partially committed states.

Concurrent Execution of Transactions

Multi-user systems:

Concurrency:

Lost Update Problem

When two transactions that update the same database items have their operations interleaved in a way that makes the value of some database item incorrect.

Example:

Transaction 1  |  Transaction 2
               |
read_item(X)   |
X := X - N     |
               |  read_item(X)
               |  X := X + M
               |
write_item(X)  <-- This is lost!
               |  write_item(X)

Temporary Update Problem

One transaction updates a database item but the transaction fails. Another transaction accesses the updated item before it is reverted to its original value.

Reading the uncommitted value is called a dirty read.

Example:

Transaction 1  | Transaction 2
read_item(X)   |
X := X - N     |
write_item(X)  |
               |  read_item(X) <- Dirty Read
               |  X := X + M
               |  write_item(X)
throw_error()  |
undo_change()  |

Incorrect Summary Problem

While one transaction is running an aggregate function while other transactions update some of the records, causing the aggregate function to read values both before and after they are updated.

ACID Properties

Atomic: a transaction is either performed entirely or not at all.

Consistent: the transaction will move the database from one consistent state to another.

Isolated: the transaction’s changes should not be visible to other transactions until it is committed - this can solve the temporary update problem.

Durable: once a transaction is committed, system failures will not cause the changes to be lost.

The concurrency system is the primary means by which the isolation property is preserved, and supports the atomicity and consistency properties.

The recovery system is the primary means by which the atomicity and durability properties are preserved, and supports the consistency and isolation properties.

Concurrency Control and Recovery

Not covered due to time limitations.