Unit 5
Unit 5
• Neither T3 nor T4 can make progress — executing lock-S(B) causes T4 to wait for T3
to release its lock on B, while executing lock-X(A) causes T3 to wait for T4 to release
its lock on A.
• Such a situation is called a deadlock.
• To handle a deadlock one of T3 or T4 must be rolled back and its locks released.
Pitfalls of Lock-Based Protocols (Cont.)
• The potential for deadlock exists in most locking protocols.
• Starvation is also possible if concurrency control manager is badly
designed. For example:
• A transaction may be waiting for an X-lock on an item, while a
sequence of other transactions request and are granted an S-lock on
the same item.
• The same transaction is repeatedly rolled back due to deadlocks.
1.Only exclusive locks are allowed. Each Transaction Ti can lock a data item at most once.
2.The first lock by Ti may be on any data item. Subsequently, a data Q can be locked by Ti only if
the parent of Q is currently locked by Ti.
3.Data items may be unlocked at any time.
4.A data item that has been locked and unlocked by Ti cannot subsequently be relocked by Ti
Graph-Based Protocols (Cont.)
• The tree protocol ensures conflict serializability as well as freedom from deadlock.
• Unlocking may occur earlier in the tree-locking protocol than in the two-phase
locking protocol.
• shorter waiting times, and increase in concurrency
• protocol is deadlock-free, no rollbacks are required
• Drawbacks
• Protocol does not guarantee recoverability or cascade freedom
• Need to introduce commit dependencies to ensure recoverability
• Transactions may have to lock data items that they do not access.
• increased locking overhead, and additional waiting time
• potential decrease in concurrency
• Schedules not possible under two-phase locking are possible under tree protocol,
and vice versa.
Timestamp-Based Protocols
• Each transaction is issued a timestamp when it enters the system. If an old
transaction Ti has time-stamp TS(Ti), a new transaction Tj is assigned time-stamp
TS(Tj) such that TS(Ti) <TS(Tj).
• The protocol manages concurrent execution such that the time-stamps determine
the serializability order.
• In order to assure such behavior, the protocol maintains for each data Q two
timestamp values:
• W-timestamp(Q) is the largest time-stamp of any transaction that executed write(Q)
successfully.
• R-timestamp(Q) is the largest time-stamp of any transaction that executed read(Q)
successfully.
Timestamp-Based Protocols (Cont.)
The transactions T1, T3 and T4 can access the database concurrently. Transaction
T2 can execute concurrently with T1 but not with either T3 or T4.
Recoverability and Cascade
Freedom
• Problem with timestamp-ordering protocol:
• Suppose Ti aborts, but Tj has read a data item written by Ti
• Then Tj must abort; if Tj had been allowed to commit earlier, the schedule is not recoverable.
• Further, any transaction that has read a data item written by Tj must abort
• This can lead to cascading rollback --- that is, a chain of rollbacks
• Solution 1:
• A transaction is structured such that its writes are all performed at the end of its processing
• All writes of a transaction form an atomic action; no transaction may execute while a
transaction is being written
• A transaction that aborts is restarted with a new timestamp
• Solution 2: Limited form of locking: wait for data to be committed before reading it
• Solution 3: Use commit dependencies to ensure recoverability
Multiversion Schemes
• Multiversion schemes keep old versions of data item to increase
concurrency.
• Multiversion Timestamp Ordering
• Multiversion Two-Phase Locking
• Each successful write results in the creation of a new version of the data
item written.
• Use timestamps to label versions.
• When a read(Q) operation is issued, select an appropriate version of Q
based on the timestamp of the transaction, and return the value of the
selected version.
• reads never have to wait as an appropriate version is returned
immediately.
Multiversion Timestamp
Ordering
• Each data item Q has a sequence of versions <Q1, Q2,...., Qm>. Each version
Qk contains three data fields:
• Content -- the value of version Qk.
• W-timestamp(Qk) -- timestamp of the transaction that created (wrote)
version Qk
• R-timestamp(Qk) -- largest timestamp of a transaction that successfully
read version Qk
• when a transaction Ti creates a new version Qk of Q, Qk’s W-timestamp and
R-timestamp are initialized to TS(Ti).
• R-timestamp of Qk is updated whenever a transaction Tj reads Qk, and
TS(T ) > R-timestamp(Q ).
Multiversion Timestamp
Ordering (Cont)
• Suppose that transaction T issues a read(Q) or write(Q) operation. Let Q denote
i k
the version of Q whose write timestamp is the largest write timestamp less than
or equal to TS(Ti).
1. If transaction Ti issues a read(Q), then the value returned is the content of
version Qk.
2. If transaction Ti issues a write(Q)
1. if TS(Ti) < R-timestamp(Qk), then transaction Ti is rolled back.
2. if TS(Ti) = W-timestamp(Qk), the contents of Qk are overwritten
3. else a new version of Q is created.
• Observe that
• Reads always succeed
• A write by Ti is rejected if some other transaction Tj that (in the serialization
order defined by the timestamp values) should read Ti's write, has already
read a version created by a transaction older than Ti.
Multiversion Two-Phase Locking
• Differentiates between read-only transactions and update transactions
• Update transactions acquire read and write locks, and hold all locks up to the
end of the transaction. That is, update transactions follow rigorous two-phase
locking.
• Each successful write results in the creation of a new version of the data
item written.
• each version of a data item has a single timestamp whose value is
obtained from a counter ts-counter that is incremented during commit
processing.
• Read-only transactions are assigned a timestamp by reading the current value
of ts-counter before they start execution; they follow the multiversion
timestamp-ordering protocol for performing reads.
Multiversion Two-Phase Locking
(Cont.)
• When an update transaction wants to read a data item:
• it obtains a shared lock on it, and reads the latest version.
• When it wants to write an item
• it obtains X lock on it then creates a new version of the item and sets this
version's timestamp to .
• When update transaction Ti completes, commit processing occurs:
• Ti sets timestamp on the versions it has created to ts-counter + 1
• Ti increments ts-counter by 1
• Read-only transactions that start after Ti increments ts-counter will see the values
updated by Ti.
• Read-only transactions that start before Ti increments the ts-counter will see the
value before the updates by Ti.
• Only serializable schedules are produced.
MVCC: Implementation Issues
• Creation of multiple versions increases storage overhead
• Extra tuples
• Extra space in each tuple for storing version information
• Versions can, however, be garbage collected
• E.g. if Q has two versions Q5 and Q9, and the oldest active transaction has
timestamp > 9, than Q5 will never be required again
Check whether the given schedule S is conflict serializable and recoverable or not
T1 T2 T3 T4
R(X)
W(X)
COMMIT
W(X)
COMMIT
W(Y)
R(Z)
COMMIT
R(X)
R(Y)
COMMIT
Check whether the given schedule S is conflict serializable
or not. If yes, then determine all the possible serialized
schedules-
T1 T2 T3 T4
R(X)
R(X)
R(X)
W(Y)
W(X)
R(Y)
W(Y)
Determine all the possible serialized
schedules for the given schedule-
T1 T2
R(A)
A=A-10
R(A)
TEMP = 0.2 * A
W(A)
R(B)
W(A)
R(B)
B = B+10
W(B)
B = B+TEMP
W(B)
Consider a relation R(A, B, C, D,
E) with the following FD’s –
AB C; BC D; CE
The number of super keys in
relation R:
1. 12
2. 8
3. 6
4. 5
In a relational data model, which one of the
following statement is true?
1. PS T
2. RT
3. PR
4. PS Q
Let S be the following schedule of operations in a
relational database system:
R2(Y),R1(X),R3(Z),R1(Y),W1(X),R2(Z),W1(Y),R3(X),
W3(Z)
Consider the statements P and Q below:
P: S is conflict serializable.
Q: If T3 commits before T1, then S is recoverable.
Which one of the following choice is correct
1. X is functionally dependent on Y
2. X is not functionally dependent
on any subset of Y
3. Both 1 & 2
4. None of the above
Consider the following two statements about database transaction schedules:
I. Strict two-phase locking protocol generates conflict serializable schedules that are
also recoverable.
II. Timestamp-ordering concurrency control protocol with Thomas Write Rule can
generate view serializable schedules that are not conflict serializable.
1. Both I and II
2. Only I
3. Only II
4. Neither I nor II
Suppose a database schedule S involves transactions T1,...,Tn. Construct the
precedence graph of S with vertices representing the transactions and edges
representing the conflicts. If S is serializable, which one of the following
orderings of the vertices of the precedence graph is guaranteed to yield a
serial schedule?
1. Topological Ordering
2. BFS
3. DFS
4. Ascending order of transaction indices
Which one of the following is NOT a part of
the ACID properties of database transactions?
1.Atomicity
2. Consistency
3. Deadlock freedom
4. Isolation
Consider the following transaction involving two bank accounts x and y.
read (x) ; x: = x - 50; write (x); read (y); y: = y + 50; write (y)
The constraint that the sum of the accounts x and y should remain
constant is that of
1. Atomicity
2. Consistency
3. Isolation
4. Durability
Which of the following scenarios may lead to
an irrecoverable error in a database system?
2. All the transactions that are already undone and redone will not be recovered.
4. The same undo and redo list will be used while recovering again.
Consider the following partial Schedule. Suppose that the
transaction T1 fails immediately after time instance 9. Which one of the
following statements is correct?
Time instance T91 T2
If a crash happens now and the system tries to recover using both undo and redo operations, what are
the contents of the undo list and the redo list?
(S1) 2RA 2WA 3RC 2WB 3WA 3WC 1RA 1RB 1WA 1WB
(S2) 3RC 2RA 2WA 2WB 3WA 1RA 1RB 1WA 1WB 3WC
(S3) 2RZ 3RC 3WA 2WA 2WB 3WC 1RA 1RB 1WA 1WB
Which of the following statements is TRUE?
(S1) 2RA 2WA 3RC 2WB 3WA 3WC 1RA 1RB 1WA 1WB
(S2) 3RC 2RA 2WA 2WB 3WA 1RA 1RB 1WA 1WB 3WC
(S3) 2RZ 3RC 3WA 2WA 2WB 3WC 1RA 1RB 1WA 1WB
Which of the following statements is TRUE?
1. 1nf
2. 2NF
3. 3NF
4. BCNF
Which of the following is TRUE?
4. BCNF
Consider the following functional dependencies in a database.
DOB→Age, Age→Eligibility, Name→Roll_number,
Roll_number→Name, Course_number→Course_name,
Course_number→Instructor, (Roll_number, Course_number)→Grade.
The relation (Roll_number, Name, Date_of_Birth, Age) is
3. In BCNF