Transactions_Lecture
Transactions_Lecture
▪ Transaction Concept
▪ Transaction State
▪ Concurrent Executions
▪ Serializability
▪ Recoverability
▪ Implementation of Isolation
▪ Transaction Definition in SQL
▪ Testing for Serializability.
T1 T2
1. read(A)
2. A := A – 50
3. write(A)
read(A), read(B), print(A+B)
4. read(B)
5. B := B + 50
6. write(B
▪ Isolation can be ensured trivially by running transactions serially
• That is, one after the other.
▪ However, executing multiple transactions concurrently has
significant benefits, as we will see later.
▪ Active – the initial state; the transaction stays in this state while
it is executing
▪ Partially committed – after the final statement has been
executed.
▪ Failed -- after the discovery that normal execution can no longer
proceed.
▪ Aborted – after the transaction has been rolled back and the
database restored to its state prior to the start of the transaction.
Two options after it has been aborted:
• Restart the transaction
▪ Can be done only if no internal logical error
• Kill the transaction
▪ Committed – after successful completion.
Schedule Schedule
3 6
▪ Serializable — default
▪ Repeatable read — only committed records to be read.
• Repeated reads of same record must return same value.
• However, a transaction may not be serializable – it may find
some records inserted by a transaction but not find others.
▪ Read committed — only committed records can be read.
• Successive reads of record may return different (but
committed) values.
▪ Read uncommitted — even uncommitted records may be read.
Connection.TRANSACTION_SERIALIZABLE)
▪ Locking
• Lock on whole database vs lock on items
• How long to hold lock?
• Shared vs exclusive locks
▪ Timestamps
• Transaction timestamp assigned e.g. when a transaction
begins
• Data items store two timestamps
▪ Read timestamp
▪ Write timestamp
• Timestamps are used to detect out of order accesses
▪ Multiple versions of each data item
• Allow transactions to read from a “snapshot” of the database