SCHEDULES in Transaction and Concurrency Control
SCHEDULES in Transaction and Concurrency Control
SCHEDULES in Transaction and Concurrency Control
Concurrency Control
UNIT-4
-Navjot Kaur
Concurrency
• When more than one transactions are executing at a time
What are the advantages of having concurrency
Waiting Time
Response Time
Resource Utilization
Efficiency
Concurrent Executions
• Multiple transactions are allowed to run concurrently in the
system. Advantages are:
• increased processor and disk utilization, leading to better transaction
throughput
• E.g. one transaction can be using the CPU while another is reading from or writing
to the disk
• reduced average response time for transactions: short transactions
need not wait behind long ones.
• Concurrency control schemes – mechanisms to achieve isolation
• that is, to control the interaction among the concurrent transactions in
order to prevent them from destroying the consistency of the database.
Why Concurrency Control is needed
• The Lost Update Problem.
This occurs when two transactions that access the same database items have their
operations interleaved in a way that makes the value of some database item
incorrect.
• The Temporary Update (or Dirty Read) Problem.
This occurs when one transaction updates a database item and then the
transaction fails for some reason. The updated item is accessed by another
transaction before it is changed back to its original value.
• The Incorrect Summary Problem .
If one transaction is calculating an aggregate summary function on a number of
records while other transactions are updating some of these records, the
aggregate function may calculate some values before they are updated and others
after they are updated.
Serializability
• Basic Assumption – Each transaction preserves database
consistency.
• Thus serial execution of a set of transactions preserves database
consistency.
• A (possibly concurrent) schedule is serializable if it is equivalent to a
serial schedule.
Serializability
• Different forms of schedule equivalence give rise to the notions of:
1. conflict serializability
2. view serializability
• Simplified view of transactions
• We ignore operations other than read and write instructions
• We assume that transactions may perform arbitrary computations on
data in local buffers in between reads and writes.
• Our simplified schedules consist of only read and write instructions.
Serializability
1. Conflict
2. View
Write(B)
Read(B)
Write(B)
Write(B)
Write(A)
Read(B)
Write(B)
Write(B) Read(A)
Write(A)
Write(A) Read(B)
Read(B) Write(B)
Write(B)
Consider a schedule:
T1 T2 T3
R(X)
R(Y)
R(X)
R(Y)
R(Z)
W(Y)
W(Z)
R(Z)
W(X)
W(Z)
Example4: is the schedule conflict serializable? Also find correct order of execution
of the instructions.
Consider a schedule:
T1 T2 T3
R(X)
R(Y)
R(X)
R(Y)
R(Z)
W(Y)
W(Z)
R(Z)
W(X)
W(Z)
Example 1: conflict equivalent
Consider a schedule:
S S1
T1 T2 T1 T2
Read(A) Read(A)
Write(A) Write(A)
Read(A) Read(A)
Write(A) Write(A)
Read(B) Read(B)
schedule S
Read(A)
Write(A)
Read(B)
Conflict Serializability (Cont.)
• Example of a schedule that is not conflict serializable: