ch2 Part1 Transactions 1
ch2 Part1 Transactions 1
Chapter 2: Transactions
Transaction Concept
Transaction State
Concurrent Executions
Serializability
Recoverability
Implementation of Isolation
Transaction Definition in SQL
Testing for Serializability.
Transaction Concept
A transaction is a unit of program execution that
accesses and possibly updates various data items.
E.g. transaction to transfer $50 from account A to
account B:
1. read(A)
2. A := A – 50
3. write(A)
4. read(B)
5. B := B + 50
6. write(B)
Two main issues to deal with:
Failures of various kinds, such as hardware failures
and system crashes
Concurrent execution of multiple transactions
Example of Fund Transfer
Transaction to transfer $50 from account A to account B:
1. read(A)
2. A := A – 50
3. write(A)
4. read(B)
5. B := B + 50
6. write(B)
Atomicity requirement
if the transaction fails after step 3 and before step 6, money
will be “lost” leading to an inconsistent database state
Failure could be due to software or hardware
the system should ensure that updates of a partially
executed transaction are not reflected in the database
Durability requirement — once the user has been notified that
the transaction has completed (i.e., the transfer of the $50 has
taken place), the updates to the database by the transaction
must persist even if there are software or hardware failures.
Example of Fund Transfer (Cont.)
Transaction to transfer $50 from account A to account B:
1. read(A)
2. A := A – 50
3. write(A)
4. read(B)
5. B := B + 50
6. write(B)
Consistency requirement in above example:
the sum of A and B is unchanged by the execution of the
transaction
In general, consistency requirements include
Explicitly specified integrity constraints such as primary
keys and foreign keys
Implicit integrity constraints
Schedule 3 Schedule 6
Conflict Serializability (Cont.)
y
Example Schedule (Schedule A) + Precedence
Graph
T1 T2 T3 T4 T5
read(X)
read(Y)
read(Z)
read(V)
read(W) T T
read(W)
read(Y) 1 2
write(Y)
write(Z)
read(U)
read(Y)
write(Y)
T T
read(Z)
write(Z) 4
3
read(U)
write(U)
T
5
Test for Conflict Serializability
A schedule is conflict serializable if
and only if its precedence graph is
acyclic.
Cycle-detection algorithms exist
which take order n2 time, where n is
the number of vertices in the graph.
(Better algorithms take order n + e
where e is the number of edges.)
If precedence graph is acyclic, the
serializability order can be obtained
by a topological sorting of the graph.
This is a linear order consistent
with the partial order of the graph.
For example, a serializability order
for Schedule A would be
T5 T1 T3 T2 T4
Test for View Serializability
The precedence graph test for conflict serializability
cannot be used directly to test for view serializability.
Extension to test for view serializability has cost
exponential in the size of the precedence graph.
The problem of checking if a schedule is view
serializable falls in the class of NP-complete problems.
Thus existence of an efficient algorithm is extremely
unlikely.
However practical algorithms that just check some
sufficient conditions for view serializability can still be
used.
Recoverable Schedules
Need to address the effect of transaction failures on concurrently
running transactions.
Recoverable schedule — if a transaction Tj reads a data
item previously written by a transaction Ti , then the
commit operation of Ti appears before the commit
operation of Tj.
The following schedule (Schedule 11) is not recoverable if
T9 commits immediately after the read