Professional Documents
Culture Documents
Dbms. 4
Dbms. 4
Dbms. 4
7, as shown in table (2).
a
Read(Sam)
Sam Sum (Sam * 20100)
Wrae(Sam) |
Reads)
Joan Joan + (Sam * 20/00)
| Wrietfoan) |
ReadSem)
Sam Sam 200,
Wieie(Sam)
ReadJoan)
Joan Joan +200 |
Wien)
Table (2: Sorially Executed Transaction (T, —>,)
.¢., processor anid disk are never idle).
SPECTRUM ALLIN-ONE JOURNAL FOR ENGINEERING STUDENTS
SIA GROUP {5‘The final amount in Sam
account is 1900. After the execution, sum of bath accounts are
preserved since they generate consistent result
Suppose, thatthe transactions are exeouted concurrently
as shown in table (3)
[ t |
| ReadSam) |
| Sam= Samm. 200 |
| Wrtersam) |
| Reaatsany
Sam~ Sam- (Same? |
| 109
| Wereesam |
|
Read aan) |
{ Joan Sean + 200, | |
| Weeetiou) |
‘Table (3k: Concurrent Execution of Transactions
Then the final amount in Sam's account is 640 and in
Joan's account is 1860 which is equivalent of executing the
transactions in the order T, -> 7.. Aflcr the execution the total
amount is stored as the exccution result in consistent sta
23. What Is a schedule? Explain about serial and
non-serial schedules.
Answer :
Schedule
Schedule is a series of actions that represent sequence
of execution. Therefore, a schedule for any set of transaction
‘comprises of instructions that aré executed by those transaction,
‘The execution order of the instructions within a transaction
is determined by a schedule (i.e. it specifies whether write
instruction should appear before or after the read instruction).
Serial Schedule
Serial schedule is a schedule wherein the transactions
are exceuted one after the another sequentially. All the
instructions belonging to a transaction appear together in serial
schedule. The number of serial schedules generated fora given
Schedule depends on the number of transaction (ie. ifthere are
‘transaction. then k! serial schedules are generated),
ENT SYSTEMS [0 BAD]
10 DATABASE MANAGEM!
nee
account is 600 and in Joan | Non-
i uted cOnCUTENIy, thy
i ions are exe a
vn
the schedule 1s not & tially executes few instructions of fig,
the operating sys CPU. performs comtext switching ang
transaction and of second transaction Lat itsviche
executes the mei onan executes the Femaining instruction,
back st ceveral transaction afe executed concur,
and 30.0 Ha is shared synchronously between all thy
then
transactions
In cone
transactions may be interleaved,
rent execution,
this, there is a possibility that more than one execution
Se seis However. it isnot possible t0 know the
sea testo that renee na ansaction bef
‘number of ins
tion.
CPU switches to another transa ;
It is not always true that concurrent execution leads to
| consistent state ie., they may be schedules that may lead to
incorrect result.
Example of one such schedule is given below,
| i 5 th
| Read Sam)
| Sam= Sam 200
i
| Reaarsam)
20
| ‘Sam:= Sam (suon 2
| Write(Sam)
write(Sam) Read(Joan) |
| Resdidoen}
Joan Joan + 200 | |
| Writeoun) A
Jo
| Write(foan) a)
‘able (2 Schedule S,
Since, the execution of above schedule results in incorrect,
state, Therefore, the sum of both accounts are not stored.
| Q24. What is a cascadeless schedule? ‘Why Is
cascadelessness of schedules desirable?
Are there any circumstances under which it
would be desirable to allow non-cascadel
schedules? Explain your answer.
Answer :
Cascadeless schedules are the schedules in which
cascading rollbacks does not occur. Cascading rollbacks is a
situation in which series of interdependent transaction rollbacks
| even ifa single transaction fails. Generally, cascading rollback
is undesirable as it may result in undoing huge amount of work.
Therefore, to avoid this undesirable situation, Cascadeless
Schedules are pre.erred.
Cascadeless schedules can more formally be defined as
a schedule in which a transaction performs'a eommit operation
Prior to read operation being performed-(on the data ites
writen Py Committed transaction) by another transaction, For
Look for the SIA GROUP Loco Gi on’the TITLE ci aa
OVER balore youtuyUNIT-4 Transaction Management, Concurrency Control
9
a
instance, consider 7, and T, as pair of transaction. 7, pert
ct rand Ty {performs
the write operation én data item ‘x" and then commits, later 7,
performs the read operation on the data item written by T,. The
important property of cascadeless scheses ts that the vchedule
are recoverable
Read (x)
Write (4)
1
Commit
: Cascadeless Schedule
Caseadcless schedules are desirable because i
schedules fate oa single asain does nat have ay
‘impact on the remaining transactions ic, even ifone transaction
fails, then it does not result in aborting the other transactions
However, the drawback of cascadeless schedules is that these
schedules provides less concurrency. Therefore. if there are
certain situations in which cascading aborts results in high
concurrency then in such situation, non-cascadeless schedules
are desirable rather than cascadeless schedules.
25. Define dynamic database. Explain phantom
problem by considering suitable example.
Answer :
Dynamic Databases
Dynamic databases are the databases th
““value-based” relationships. In these database, the information
about the relationship and the location where the records are
stored are specified at the execution time (.c., retrieval time).
Phantom Problem
Ifa transaction is executed twice without undergoing
modifications on any of the tuples and if different result is
‘generated at each execution, then such an execution leads to
the occurrence of phantom problem.
Example
Consider a transaction 7, that scans “STUDENT”
relation in order to find the student who secured highest marks
sn subject! and subject2. Before initiating the search progess,
the transaction finds all the pages associated with “STUDEN[”
relation and then acquire locks on each of the page consisting of
student with subject! After acquiring the lock, the transaction
searches the locked pages to find the page consisting ofa student
with highest marks which is, for instance 92. In the meantime,
another transaction 7, performs an insertion operation by
inserting new student record with subject! and marks 95
onto a page that does not contain other student with subject.
r
’
consists of
t.
of transactions 7, and T,. Eventhough, both the
employ strict 2PL, they fail to ensure seralizability: This is
because the implicit assumption made by transaction I, which
assumes that it has locked all pages consisting of student with
subject! But, the assumption fils when
by transaction 7, on different page. Thus, when execution of
411
8, Aer finding the desired record, the transaction 7, deletes
this student record. Once the record is deleted, the transaction 7,
commits and releases all the acquired locks. Finally, transaction
T, sdentifies and locks all the pages consisting of student with
tbject2. Then the transaction finds the record ofa student who
cured the highest marks (ie. *7)
The result generated ater the execution of transaction 7,
and 87, However. ithe order of executions 7, > Try then
he es generated willbe 92 ane 93 and ifthe order is, >
then te result generated will bs 95 and 87. Therefore, ean
be said that the result generated after the interleaved execution
after the serial execution
transactions
is different from the result generat
new record is inserted
same transaction, generates different result at each execution,
then phantom problem is encountered
‘The phantom problem can he prevented by allowing
the DBMS to lock all the rows that consists of subject! on
behalf of transaction T,, This can be done by locking the entire
“STUDENT” table, However, such locking does not guarantee
high level of eancurreney. =
Q26. Explain B’-treé locking used for concurrency
control with suitable example.
Concurrency Control Using R-tree
Concurrency control using B”-tree can be achieved by.
()__ Ignoring the structure of the index.
(it) Considering every individual page as date object
(iii) Applying some version of 2PL.
‘The result of employing B°-tree concurrency control
approach is that a high lock contention exist in the higher level
nodes of the tree. This is because the search provess initiates
from the root node and continues to the leaf node by following
‘ particular path, In addition to this locking protocol, there
‘exists many efficient locking protocols that empioy hierarchical
tree index structure. These protocols ate capable of achieving,
serializability and recoverability when locking overhead is being
reduced.
Following two observations must be considered while
using any of the locking protocols,
Searching is directed by the higher level nodes and the
Since, the new student record is inserted on a different page, | (jy
‘acquiring an exclusive lock on this page does not conflict with actual data is present in the leaf node.
any of the locks acquired by the first transaction ie. 7,.Now. | | - :
sa scton 7, vans stent elton and findsall the pages | (i) Wille ineting a data vale, ts neceaary to acquire
consisting of student with subject2. After identifying the pages, aan exclusive lock on a node, if there is a possibility fora
split to propagate back from the modified node to reach
ese pages and then finds the student
sin subject2, which is, forinstance
transaction 7, logks all th
who secured the highest marks
SPECTRUM Ajj -ONE JOURNAL FOR ENGINEERING STUDENTS
the root node.
SiA GroupDATABASE MANAGEMENT SYSTEMS [JNTU-HYDERABaq,
yhich Pa
ing the search process, every tree node ic, from root node to the desired tat nde = a day,
‘auc i present) must acquire a separate shared lock. However, tis necessary 1 ensue that, when a ere bo
the lock acquired by its parent lock is released. The Purpose of releasing the lock as soon as child node #eq} cause
the seach press cannot propagate in backward direction (ie, the node visited wil not be revisited)
which an “X'lock is acquited by every noge
While inserting a dat value, a conserys ti -
being traversed from root node to the oa oe nee ioe pecans in the backward direction ic, frp,
odie eto heron, Thelok acquired the pare rode isnot released if there is possibility thatthe split may propagy
to the parent node. In other words it can be Said, the lock is teleased only if the child node has space for inserting new data Value
Te ces of asquiring the lock om chill nde andthe releasing the lock aequired by parent node is called Inck coupling op
crabbing
Example
Consider the following B'-tree.
Tr
WL
\ ae
etl Ee
rin last ts da aby a Bah
. Figure: B- tree Locking
Ifthe data value 80° is tobe searched, then the transaction T, reads the values present in node ‘A, after acquiring a shared
lock (S) om it If the node contains the desired value then the search operation terminates, However, iit docs not cern the
required data valu, then the transaction proceeds to node ‘Nand acquires an ‘Sloe on it Once the transaction acquires lock
00 the lock on node “Mis released. The transaction proceeds to node ‘O" as ‘N” doesnot have the resuired data value, The
Process of acquiring and releasing the lock continues until the node ‘P” containing the data value $0* is reached. The purpose of
‘acquiring lock on each node which i being searched iso allow newer transactions to wait until the. currently executing transaction
completes. For example, ifa transaction 7, wants to delete the data value 50*, then it has to wait until T, completes, but if another
‘ransaction T- have already aequited lock on node “O" before 7, then T, has to wait fo the transaction 7. o complet.
Inorder to insert 46°, a transaction 7, must intially acquire a‘S"lock on node ‘M, then on node ‘N”. Once node ‘'W acquire
fe lock, the lock on node “AF must be released. The transaction proceeds and acquires a'S lock onthe next node ie, node -o*
Before releasing the ‘S Tock on node ‘N’, the transaction acquires an‘X" lock onthe successive node of node ‘OP ie, node P
Once the lock has been acquited the locks are released in the order node ‘O” and then node "N’. The data value 46+ i inserted in
the node “P’ as it has space for new data entry. A
However, ifa data valu isto be inserted within a node “U" that is already ful then the node “U” must be splitted. Spliting
means that the parept of node ‘U? ie. node ‘7 must undergo modifications. But, this parent node "is locked using the shared
lock, therefore, node “7, must send a request for upgrading its ‘S'lock to an “X* lock. The request is granted only if no other
transaction holds an ‘Jock on node “T when the leaf node °U” is being split, the new node must be added tothe left of U. But,
if the new node Is added as the right child of node U, then it is necessary to change the sibling pointer of successive node ie.
ode ‘R’ which has different parent node.
This concurrency approach is better than 2PL, but the disadvantage ofthis approach is that performance is degraded as
many ‘X locks are unnecessarily acquired eventhough they are released quickly. This problem can be solved by acquiring only
“S*lock on all nodes except in the leaf node that acquired an “X" lock. In this approach, spitting isnot required in many situations
‘When the leaf node does not have space for inserting a new data value, then itis necessary to upgrade the shared locks to exclusive
locks which are acquired by every node to which the split propagates.
Look for the SUA GROUP LOGO { on the TITLE COVER before you buy
fr
;UNIT-4 Transaction Management, Concurrency Control
—_—___——nnmrrsorment Concurrency Control
4.4 SERIALIZABILITY, RECOVERABILITY
Q27. What is serializability? Explain.
May-19(R16), 0940)
oR
Define serializability. Explain conflict
erlalizability and view serializabllity in detall.
Answer : June-144R09), 8
Serializability
Senializability isa standard that ensures the consistencs
ofa schedule A schedule is consistent if and only itt
serializable. A schedule is serializable if the interleaved
transactions produce the result, which is equivalent tothe result,
Produced by executing individual transaction separately (i.e.
4 schedule is serializable, ifit produces the same result as that
ofa serial schedule),
Example
ses
i
fi
l eeoid]
‘Table (1): Serial Schedule
n n
Reach) | |
=
| Resa
| i
sent
vn
Aaa
we
‘Table (2) Schedule for the Two Transactions When Interleaved
‘The above two schedules produce the same result hence
they are serializable. The transaction may be interleaved in any
‘order and DBMS doesn’t provide any guarantee about the order,
in which they are executed.
The two different types of serializability are,
1. Conflict serializability
2. View serializability.
1. Conflict Serializabitity
Consider a schedule S,, consisting of two successive
instructions J, and /, belonging to transactions 7, and 7,
respectively. If /, and /, refer to different data item then i i
very easy to swap these instructions. The result of swapping
these instructions, doesn’t have any impact on the remaining
instructions in the schedule. On the other hand, if /, and J,
refer to same data item then the following four cases. must be
considered (since only read and write operations are performed),
SPECTROM ALLN-ONE JOURNAL FOR ENGINEERING STUDENTS
(i) 1,= Read(s), 1, = Reads)
(i) 1, = Read(e), J, ~ Write(s)
(Gli) 1, Writetx), 1, = Read(x)
iv) 1, = Write(a), J, = Write(2)
Case ()
Here, both J, and J, are read instructions, In this case, the
«execution order ofthe insinctions isnot considered Since the same
data item xis read by both the transactions , and 7, (ie, ether 7,
can read the instruction 1, before T, reads fo vice versa).
Case (ty
Here 1, and [reread and write instructions respectively.
Ifthe execution ordet of instruction is /,-» then transaction 7,
canmot read the value written by transaction in instruction 1,
On the other hand, if the execution order is /, -/, then 7, can
read the value written by transaction 7,. Therefore in this case,
the execution order of instruction is important.
Case it)
Here, 1, and , are write and read instruction respectively.
Ifthe execution order of instruction is /,—» I, then transaction 7,
can read the value written by 7, but if the order is /, -¥ J, then
T, cannot read the value written by transaction T,, Therefore
in this case, the execution order of instructions is important.
Case (iv)
Here, both 1, and J, are write instructions. n tis case.
the order of instruction doesn’t matter. If a read operation is
performed before the write operation, then the vata item which
‘was already stored in the database is read. Now, if write(x)
‘operation is performed on the database, then already stored data
item is overwritten by new data item x. Then a read(x) operation
is performed, such thatthe data item x is read but not the earlier
stored value. This is because, database stores only the current
result. If there is no next wrte(x) instruction after the two write
instructions in S,, then the execution order of the instruction have
«impact on the resultant value of x, stored in the database
‘Two instructions J, and J, are said to be conflicting if
and only if,
1. They representthe operations performed by two different
transactions on the same data item.
At least one among J), and J, is a write operation,
Consider the following schedule S,,
7 1 |
Read(x) |
‘Write(x)
Reads) |
wee
Ready) |
‘Write(y)
el
Write(y)
Table (3): Schedule S,{
|
|
|
4.14
the write(x) operation of 7, conflicts with read(x)
operation of 7, But the wrte(x) operation of 7, doesn’t contlict
with read) operation of 7, since these instructions perform
their operations on two different data items
Conflict Equivalent
‘The order
ofthe instructions /, and J, can be swapped
°
°
4, and 1, belong to two diferent transactions
1, and J, are not conflicting instructions,
The exceution order ofthe instuction in schedule 5,
Ae swapped, so as to generate a new schedule S° which i
eauivalent to schedule S,.5, is said to be equivalent to $.
because the order of executing the instucton in Sis similar
tothe execution order in S except forinstuction and, ('e
the order of J, and /, is not considered). aie
Inthe above schedule 5, wrte(x) instruction of 7,can be
swapped with ready) instruction of 7, (since both instructions
are non-conflicting). This schedule S, can be transferred into
‘Sy by swapping the instruction of 7, and 7, in the following
‘manner,
()__Read() instruction of 7, doesn’t conflict with read(x)
instruction of 7,, Therefore, these instructions ean be
‘swapped so as to generate new schedule S,"
(ii) Write(») instruction of 7, can be swapped with wrte(x)
instruction of T,. Since, these are nonconflicting
instructions.
(iii) Write(») instruction of 7, can further be swapped with
read) instruction of 7,
‘After performing the swapping, a new schedule S,"is
produced which is a serial schedule.
Tt
Reads)
Write(x)
Ready)
Write(y)
Table (4: Schedule S;
Since, S, is equivalent to 5S,’ therefore S, and'S,” are said
to be conflict equivalent. In general, two schedules S, and 5,"
are said to be conflict equivalent when itis possible to generate
1 schedule $,” from S, by performing a series of swapping
‘operations on nonconflicting pair of instructions.
The conflict equivalence lead to another notion called
conflict serialisability. A schedule say 5, is conflict serializable
only if it is conflict equivalent with the serial schedule.
DATABASE MANAGEMENT SYSTEMS [INTU-HYDERABAp,
Tn the above example, schedule S, is conflict
serializabe
as itis conflict equivalent witha serial schedule S
Consider a schedule S, which is not conflict serializabje
[1 tr |
Reads) — | |
Write) |
‘Write(x) |
al (5 Sehodle 8,
‘The above schedule 5, is not conflict serializable since
itis not equivalent to either of the serial schedules «7,, T,> or