EE DBMS Unit3
EE DBMS Unit3
Transaction Concept
Transaction State
Concurrent Executions
Serializability
Recoverability
Implementation of Isolation
Transaction Definition in SQL
Testing for Serializability.
Database System Concepts - 7th Edition 17.2 ©Silberschatz, Korth and Sudarshan
Transaction Concept
Database System Concepts - 7th Edition 17.3 ©Silberschatz, Korth and Sudarshan
Example of Fund Transfer
Database System Concepts - 7th Edition 17.4 ©Silberschatz, Korth and Sudarshan
Example of Fund Transfer (Cont.)
Database System Concepts - 7th Edition 17.5 ©Silberschatz, Korth and Sudarshan
Example of Fund Transfer (Cont.)
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.
Database System Concepts - 7th Edition 17.6 ©Silberschatz, Korth and Sudarshan
ACID Properties
A transaction is a unit of program execution that accesses and possibly
updates various data items. To preserve the integrity of data the database
system must ensure:
Atomicity. Either all operations of the transaction are properly reflected in
the database or none are.
Consistency. Execution of a transaction in isolation preserves the
consistency of the database.
Isolation. Although multiple transactions may execute concurrently, each
transaction must be unaware of other concurrently executing transactions.
Intermediate transaction results must be hidden from other concurrently
executed transactions.
• That is, for every pair of transactions Ti and Tj, it appears to Ti that either
Tj, finished execution before Ti started, or Tj started execution after Ti
finished.
Durability. After a transaction completes successfully, the changes it has
made to the database persist, even if there are system failures.
Database System Concepts - 7th Edition 17.7 ©Silberschatz, Korth and Sudarshan
Transaction State
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.
Database System Concepts - 7th Edition 17.8 ©Silberschatz, Korth and Sudarshan
Transaction State (Cont.)
Database System Concepts - 7th Edition 17.9 ©Silberschatz, Korth and Sudarshan
Concurrent Executions
Database System Concepts - 7th Edition 17.10 ©Silberschatz, Korth and Sudarshan
Schedules
Database System Concepts - 7th Edition 17.11 ©Silberschatz, Korth and Sudarshan
Schedule 1
Let T1 transfer $50 from A to B, and T2 transfer 10% of the balance from
A to B.
A serial schedule in which T1 is followed by T2 :
Database System Concepts - 7th Edition 17.12 ©Silberschatz, Korth and Sudarshan
Schedule 2
Database System Concepts - 7th Edition 17.13 ©Silberschatz, Korth and Sudarshan
Schedule 3
Database System Concepts - 7th Edition 17.14 ©Silberschatz, Korth and Sudarshan
Schedule 4
Database System Concepts - 7th Edition 17.15 ©Silberschatz, Korth and Sudarshan
Serializability
Database System Concepts - 7th Edition 17.16 ©Silberschatz, Korth and Sudarshan
Simplified view of transactions
Database System Concepts - 7th Edition 17.17 ©Silberschatz, Korth and Sudarshan
Conflicting Instructions
Database System Concepts - 7th Edition 17.18 ©Silberschatz, Korth and Sudarshan
Conflict Serializability
Database System Concepts - 7th Edition 17.19 ©Silberschatz, Korth and Sudarshan
Conflict Serializability (Cont.)
Schedule 3 Schedule 6
Database System Concepts - 7th Edition 17.20 ©Silberschatz, Korth and Sudarshan
Conflict Serializability (Cont.)
Database System Concepts - 7th Edition 17.21 ©Silberschatz, Korth and Sudarshan
View Serializability
Let S and S’ be two schedules with the same set of transactions. S and S’
are view equivalent if the following three conditions are met, for each data
item Q,
1. If in schedule S, transaction Ti reads the initial value of Q, then in
schedule S’ also transaction Ti must read the initial value of Q.
2. If in schedule S transaction Ti executes read(Q), and that value was
produced by transaction Tj (if any), then in schedule S’ also
transaction Ti must read the value of Q that was produced by the
same write(Q) operation of transaction Tj .
3. The transaction (if any) that performs the final write(Q) operation in
schedule S must also perform the final write(Q) operation in schedule
S’.
As can be seen, view equivalence is also based purely on reads and writes
alone.
Database System Concepts - 7th Edition 17.22 ©Silberschatz, Korth and Sudarshan
View Serializability (Cont.)
Database System Concepts - 7th Edition 17.23 ©Silberschatz, Korth and Sudarshan
Other Notions of Serializability
Database System Concepts - 7th Edition 17.24 ©Silberschatz, Korth and Sudarshan
Recoverable Schedules
If T8 should abort, T9 would have read (and possibly shown to the user) an
inconsistent database state. Hence, database must ensure that schedules
are recoverable.
Database System Concepts - 7th Edition 17.25 ©Silberschatz, Korth and Sudarshan
Cascading Rollbacks
Database System Concepts - 7th Edition 17.26 ©Silberschatz, Korth and Sudarshan
Cascadeless Schedules
Database System Concepts - 7th Edition 17.27 ©Silberschatz, Korth and Sudarshan
Concurrency Control
A database must provide a mechanism that will ensure that all possible
schedules are
• either conflict or view serializable, and
• are recoverable and preferably cascadeless
A policy in which only one transaction can execute at a time generates
serial schedules, but provides a poor degree of concurrency
• Are serial schedules recoverable/cascadeless?
Testing a schedule for serializability after it has executed is a little too late!
Goal – to develop concurrency control protocols that will assure
serializability.
Database System Concepts - 7th Edition 17.28 ©Silberschatz, Korth and Sudarshan
Concurrency Control (Cont.)
Database System Concepts - 7th Edition 17.29 ©Silberschatz, Korth and Sudarshan
End of Chapter 17
Database System Concepts - 7th Edition 17.30 ©Silberschatz, Korth and Sudarshan