19 - Transaction Management Part 2
19 - Transaction Management Part 2
Part 2
Serializability
In a database system, we can have number of
transaction processing. Related transactions will be
processed one after another. There are some transactions
processes in parallel. Some of the transactions can be
grouped together.
A schedule is a process of grouping the transactions
into one and executing them in a predefined order. A
schedule is required in a database because when some
transactions execute in parallel, they may affect the
result of the transaction - means if one transaction is
updating the values which the other transaction is
accessing, then the order of these two transactions will
change the result of second transaction. Hence a
schedule is created to execute the transactions.
A schedule is called serial schedule, if the transactions
in the schedule are defined to execute one after the other.
Even when we are scheduling the
transactions, we can have two transactions
in parallel, if they are independent. But if
they are dependent, then the results will
change.
For example, say one transaction is
updating the marks of a student in one
subject; meanwhile another transaction is
calculating the total marks of a same
student.
If the second transaction is executed
after first transaction is complete, then
both the transaction will be correct.
But what if second transaction runs
first? It will have wrong total mark.
This type of incorrect processing of transaction
needs to be handled in the system. Parallel
execution of transaction is allowed in the
database only if there is any equivalence
relation among the transactions.
78 222
There are three types of equivalence
relation among the transactions – Result,
View and Conflict Equivalence.
Result Equivalence: - If the two
transactions generate same result after their
execution then it is called as result
equivalence.
For example, one transaction is updating
the marks of Student X and the other
transaction is to insert a new student. Here
both the transactions are totally independent
and their order of execution does not matter.
Whichever order they are executed; the result
is the same. Hence it is called result
equivalence transactions.
View Equivalence: -Two schedules are
said to be view equivalence, if the transaction
in one schedule is same as the one in other.
That means, both the transactions in two
schedules perform same tasks.
T2: lock-S(A);
read (A);
unlock(A);
lock-S(B);
read (B);
unlock(B);
display(A+B)
Two Phase Locking Protocol (2PL): - In this type of protocol, as the
transaction begins to execute, it starts requesting for the locks that it
needs. It goes on requesting for the locks as and when it is needed. Hence
it has a growing phase of locks. At one stage it will have all the locks.
Once the transaction is complete it goes on releasing the locks. Hence it
will have descending phase of locks. Thus this protocol has two phases:
Phase1: Growing phase of locks,
Phase 2: Shrinking phase of locks.
For example, if we have to calculate total marks of 3
subjects, then this protocol will go on asking for the locks
on subject1 marks, subject2 marks and then subject3
marks.