Unit 3
Unit 3
Scheduling
Definition
Types of Schedules
1. Serial Schedule
2. Non-serial Schedule
Types of Schedules
Types of Schedules
Types of Schedules
Types of Schedules - Serial Schedule
Example:
Types of Schedules - Serial Schedule
Example:
Consider two transactions T1 and T2 shown above, which
perform some operations. If it has no interleaving of
operations, then there are the following two possible
outcomes.
Types of Serializability:
• Conflict Serializability
• View Serializability
Serializability
Conflict Serializability
A schedule is called conflict serializable if it can be
transformed into a serial schedule by swapping non-
conflicting operations.
Example:
• Read i(x) read j(x) - non conflict read-read operation
View Serializability
• A schedule is viewed serializable if it is view
equivalent to a serial schedule.
• If a schedule is conflict serializable, then it will be
view serializable.
• The view serializable which does not conflict with
serializable, contains blind writes.
Serializability
View Equivalent
Two schedules S1 and S2 are said to be view
equivalent if they satisfy the following conditions:
1. Initial Read
2. Updated Read
3. Final Write
Serializability
1. Initial Read
An initial read of both schedules must be the same.
Suppose two schedule S1 and S2. In schedule S1, if a
transaction T1 is reading the data item A, then in S2,
transaction T1 should also read A.
Note: Above two schedules are view equivalent because Initial read
operation in S1 is done by T1 and in S2 it is also done by T1.
Serializability
2. Updated Read
In schedule S1, if Ti is reading A which is updated by Tj
then in S2 also, Ti should read A which is updated by Tj.
Note: Above two schedules are not view equal because, in S1,
T3 is reading A updated by T2 and in S2, T3 is reading A updated
by T1.
Serializability
3. Final Write
A final write must be the same between both the
schedules. In schedule S1, if a transaction T1 updates A at
last then in S2, final writes operations should also be done
by T1.
that will be $300 only because TX didn't update the value yet.
• At time t2, transaction TY reads the value from account A, i.e., $300.
• After that, at time t5, transaction TX reads the available value of account
A, and that will be read as $400.
• It means that within the same transaction TX, it reads two different
values of account A, i.e., $ 300 initially, and after updation made by
transaction TY, it reads $400. It is an unrepeatable read and is therefore
known as the Unrepeatable read problem.
Concurrency Control
Concurrency Control Protocols
• The concurrency control protocols ensure the atomicity,
consistency, isolation, durability and Serializability of the
concurrent execution of the database transactions.
2. Exclusive lock:
• In the exclusive lock, the data item can be both reads
as well as written by the transaction.
• This lock is exclusive, and in this lock, multiple
transactions do not modify the same data
simultaneously.
Concurrency Control
There are four types of lock protocols available
1. Simplistic lock protocol
2. Pre-claiming Lock Protocol
3. Two-phase locking (2PL)
4. Strict Two-phase locking (Strict-2PL)
Concurrency Control
1. Simplistic lock protocol:
It is the simplest way of locking the data while
transaction. Simplistic lock-based protocols allow all the
transactions to get the lock on the data before insert or delete
or update on it. It will unlock the data item after completing the
transaction.
Concurrency Control
2. Pre-claiming Lock Protocol
Concurrency Control
2. Pre-claiming Lock Protocol
• Pre-claiming Lock Protocols evaluate the transaction to list
all the data items on which they need locks.
• Before initiating an execution of the transaction, it requests
DBMS for all the lock on all those data items.
• If all the locks are granted then this protocol allows the
transaction to begin. When the transaction is completed then
it releases all the lock.
• If all the locks are not granted then this protocol allows the
transaction to rolls back and waits until all the locks are
granted.
Concurrency Control
3. Two-phase locking (2PL)
• The two-phase locking protocol divides the execution
phase of the transaction into three parts.
• In the first part, when the execution of the transaction
starts, it seeks permission for the lock it requires.
• In the second part, the transaction acquires all the locks.
The third phase is started as soon as the transaction
releases its first lock.
• In the third phase, the transaction cannot demand any new
locks. It only releases the acquired locks.
Concurrency Control
3. Two-phase locking (2PL)
Concurrency Control
3. Two-phase locking (2PL)
There are two phases of 2PL:
Growing phase:
In the growing phase, a new lock on the data item may
be acquired by the transaction, but none can be released.
Shrinking phase:
In the shrinking phase, existing lock held by the
transaction may be released, but no new locks can be
acquired.
Concurrency Control
Transaction T1:
Growing phase : from step 1-3
Shrinking phase : from step 5-7
Lock point : at 3
Transaction T2:
Growing phase : from step 2-6
Shrinking phase : from step 8-9
Lock point : at 6
Concurrency Control