Dda Ec3
Dda Ec3
Applications
Ie., 1000/100
Optimized
tree
Session 8 TRANSACTIONS
TUTORIAL
LEARNING OUTCOME
Introduction to transactions
States of a transaction
Desirable properties of a transaction
Schedules
Concurrent transactions
Serializability
REFER: T1-Chapter 17
Sections: 17.1- 17.6
UPDATE account
SET bal = bal + 1000
WHERE acno = 200;
COMMIT;
SELECT * FROM account;
Initial:
Acno bal
155 3000
200 5000
Output:
acno bal
155 2000
200 6000
A)
S1 s2
S: R1(x), R2(x),R1(z),R3(x),R3(y),W1(x),c1,W3(y),c3,R2(y),W2(z),W2(y),c2
S: R1(x), R2(x),R1(z),R3(x),R3(y),W1(x),c1,W3(y),c2,R2(y),W2(z),W2(y),c3
S: R1(x), R2(x),R1(z),R3(x),R3(y),W1(x),c1,W3(y),c2,R2(y),W2(z),W2(y),c2
a. R1(x), R2(z),R3(x),R1(z),R2(y),R3(y),W1(x),c1,W2(z),W3(y),W2(y),c3,c2
b. R1(x),W1(x),R2(x),R1(y),R2(y),W2(x),W1(y),a1,a2
c. R1(x),W1(x),R2(x),R1(y),W2(x),c2,a1
d. R1(x),R2(x),W1(x),R1(y),W2(x),c2,W1(y),c1
e. R2(x),R1(x),W1(x),R1(y),W1(y),c1,W2(x),c2
•If any two schedules generate the same result after their
execution, then they are called as result equivalent schedules.
•This equivalence relation is considered of least significance.
•This is because some schedules might produce same results for
some set of values and different results for some other set of
values.
Let X = 2 and Y = 5.
On substituting these values, the results produced by each schedule
are-
States of a transaction
Desirable properties of a transaction
Schedules
Concurrent transactions
Serializability
• This property ensures that multiple transactions can occur simultaneously without
causing any inconsistency.
• During execution, each transaction feels as if it is getting executed alone in the
system.
• A transaction does not realize that there are other transactions executed in parallel
• Changes made by a transaction becomes visible to other transactions only after they
are written in the memory.
• The resultant state of the system after executing all the transactions is same as the
state that would be achieved if the transactions were executed serially one after the
other.
• It is the responsibility of concurrency control manager to ensure isolation for all
the transactions.
If WTS(A) > TS (Ti), then Ti Rollback • R1(X) W 2(X) timestamp (TS) will come first in
execution sequence than Transaction
• W 1(X) R2(X) with higher TS.
Else (otherwise) execute R(A) operation and SET RTS (A) = MAX • W 1(X) W 2(X)
{RTS(A), TS(Ti)} •Allowed
Rules No.2 is used when a transaction needs to perform WRITE (A) • All operations where T2 occurs before T1.
• R1(X) R2(X)
If RTS(A) > TS (Ti), then Ti Rollback
If WTS(A) > TS (Ti), then Ti Rollback
Else (otherwise) execute W(A) operation and SET WTS (A) =
TS(Ti)
Where “A” is some data
Thomas Write Rule does not enforce Conflict Thomas Write Rule
Serializability but rejects fewer Write •Not Allowed
Operations by modifying the check • R1(X) W 2(X)
Operations for W_item(X) • W 1(X) R2(X)
•Allowed
If R_TS(X) > TS(T), then abort and roll back T and • All operations where T2 occurs before
reject the operation. T1.
If W_TS(X) > TS(T), then don’t execute the Write • Outdated Writes: W 1(X) W 2(X)
Operation and continue processing. This is a case of
Outdated or Obsolete Writes. Remember, outdated • R1(X) R2(X)
writes are ignored in Thomas Write Rule but a
Transaction following Basic TO protocol will abort
such a Transaction.
If neither the condition in 1 or 2 occurs, then and only
then execute the W_item(X) operation of T and set
W_TS(X) to TS(T)
Thomas Write rule doesn’t allow conflict serializable schedule but only allows “view
serializable” schedules!!!
Locks will always be acquired from the At the table level, there are five different types of locks:
top to the bottom as in that way SQL At the row level, the following three lock •Exclusive (X)
Server is preventing a so-called Race •Shared (S)
condition to occur.
modes can be applied:
•Exclusive (X) •Intent exclusive (IX)
Not all lock modes can be applied at all
levels. •Shared (S) •Intent shared (IS)
•Update (U) •Shared with intent exclusive (SIX)
Concurrency
Concurrent protocols
Deadlock and recovery
Session 10 DB RECOVERY
TUTORIAL
RECOVERY
VS
Session 11 DB Security
TUTORIAL
DB SECURITY