We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 44
Transaction
e Management
1. Transaction Concept
A transaction is a unit of program execution that accesses and
possibly updates various data items. A transaction results from
the execution of a user program written in a high level data
manipulation language or programming language (for e.g. SQL,
COBOL, C, PASCAL) and is delimited by statements of the
form begin transaction and end transaction. The transaction
consists of all operations executed between begin and end of the
transaction.
For example: A transaction includes read and write operations to access and update the database.
a132 / when Relational Database
2.
Transaction Properties
Transactions should have several properties. These are called the ACID properties and they
should be enforced by the concurrency control and recovery methods of the DBMS.
The following are the ACID properties of transactions:
1
3.
4
Atomicity: A transaction is treated as a unit of operation.
Either all the transactions actions are completed or none
of them are. It is also known as ‘all-or-nothing property’.
If the transaction fails to complete for some reason, the
recovery manager must undo any effects of the transaction
of the database.
Consistency: The consistency of a transaction is simply | Wyhatls Neneacton’
its correctness.
It implies that if the database was in a consistent state before the start of a transaction then
on termination of a transaction the database will also be in a consistent state.
Each transaction, run by itself with no concurrent execution of other transactions, must
preserve the consistency of database. This property must hold for each transaction,
‘The user’s who submits the transaction must ensure that when run to competition by itself
against a consistent database instance, the transaction will leave the database in a
consistent state.
For example, the fund transfers between bank accounts should not change the total
amount of money in the accounts. To transfer money from one account to another, a
transaction must debit one account, temporarily leaving the database inconsistent in a
global sense, even though the new account balance may satisfy any integrity constraints
with respect to the range of acceptable account balances. The user’s notion of a consistent
database is preserved when the second account is credited with the transferred amount.
Isolation: It indicates that actions performed by a transaction will be isolated or hidden
from outside the transaction until the transaction terminates. It gives the transaction a
measure of relative independence.
Durability: It ensures that once a transaction commits, its results are permanent and
cannot be erased from the database. These changes must not be lost because of any failure.Transaction Management wfion\ 3-3
. Transaction States
transaction is an atomic unit of work that is either completed
= its entirety or not done at all. For recovery purposes, the
‘stem needs to keep track of when the transaction starts,
‘emninates, and commits or aborts. A transaction that completes
Be execution successfully is called as a committed transaction.
‘The committed transaction should always take the database to
‘Se new consistent state. The changes made by the committed
Explain states of
. : ‘ ‘transaction with the help
‘ansaction should be permanently stored in the database even if of suitable diagram.
‘Gere is any system failure.
“4 database transaction is a logical unit of database operations which are executed as a whole
so process user requests for retrieving data or updating the database.
‘There are five states of transaction:
4. BEGIN: The transaction on the database begins by the execution of the first,statement of
the transaction that is it becomes active.
2 ACTIVE: In this state, the transaction is modifying the database state. In this state, the
transaction is performing read or write operations on database state. At the end of this
state the transaction will enter into three states, i.e., start, commit, abort or error.
3. COMMIT: In the start-commit state, the transaction instructs the DBMS to reflect the
change into the database. Once these changes are done in database the transaction is said
to be in a commit state.
4. ROLLBACK: It may be possible that all changes made by the transaction are not
reflected top the database due to any kind of failure. In this situation, transaction go to
abort or error state. An aborted transaction that made no changes to the database is
terminated without the need for rollback.
¥
END: A transaction can end in three different states:
a. Successful termination: A transaction ends after a commit operation.
b. Suicidal termination: A transaction detects an error during its processing and thus
aborts and performs a rollback operation.
Murderous termination: The operating system or the DBMS can force the
transaction to be aborted for any reason.Partially
Committed Conant
System
failure
Database
Modified
Error Detected
during transaction
Consistent
State
Database unmodified
Figure 3.1: Different states of a transaction
4. Concurrent Execution
Transaction processing systems usually allow multiple transactions to run concurrently.
Concurrent execution of multiple transactions causes several complications with the consistency
of data and may result in some inconsistent database, whereas serial execution of transactions is
much easier to implement and maintain the consistency of database.
Read (X)
Write (x)
Read (Y)
Write (Y)
Read (Z)
Write (2)
Aschedule involving two transactions
The schedule shown above represents an interleaved execution of two transactions. Ensuring
transactions isolation while permitting such concurrent execution is difficult, but is necessary for
performance reasons.Transaction Management wsion\ 35
Following are the two advantages of concurrent execution:
L
Problems in Concurrent Execution
i:
Improved resource utilization and throughput: While one transaction is waiting for a
page to be read from disk, the CPU can process another transaction. This is because /O
activity can be done in parallel with CPU activity in a computer. Overlapping /O and
CPU activity reduces the amount of time disks and processors are idle and increases
system throughput.
Throughput is the number of transactions executed in a given amount of time. Because of
this resource utilization has also increased as the idle time is reduced.
Reduced waiting time: There is mix of transactions running on a system. Some
transaction may be short and some long. If transactions are run serially short transaction
may have to wait for a preceding long transaction to complete. But if we run them
concurrently then the waiting time of short transaction is reduced. It also reduces the
average response time. Average response time is the average time of the transaction to be
completed after it has been submitted.
A schedule involving consistent, committed transactions
could run against a consistent database and leave it in an
inconsistent state.
Two actions on the same data object conflict if at least one of them is write.
‘The three situations can be described in terms of when the actions of two transactions TO
and T1 conflict with each other.
i. Reading uncommitted data (WR conflicts): A transaction T1-could read a database
object X that has been modified by another transaction TO which has not yet
committed. Such a read is called a dirty read.
For example, consider two transactions TO and Ti each of which run alone,
preserve database consistency. Transactions TO transfer 200 Rs. from account X to
Y and transaction TI add both X and Y by 8% interest to each account,Read (X)
X=X+(X*0.8)
Write (x)
(vy) | Read(Y)
Y =Y+ 200 | Y=Y+(¥*0.8)
Write (Y)
that.
foes
Read (X)
X= X -200
Write (X)
The account transfer transaction TO deducts 200 Rs. from account X. The interest
deposit transaction T1 reads current value of accounts X and Y and adds 8 %
inertest to each. The account transfer transaction T1 credits 200 Rs. to account Y.
The problem is that:
a. Transaction TO may write some value for X that makes database inconsistent.
b. As long as TO overwrites this value with a correct value of X before
committing no harm is done if.
TO and T1 run in same serial order because transaction T1 would not see the
temporary inconsistency. y
c. Its interleaved execution can expose this inconsistency and lead to an
inconsistent final database state.
Unrepeatable Reads (RW conflicts): A transaction T1 could change the value of an
object X that has been read by transaction TO while T1 is still in progress.Transaction Management fin \ 3-7
Transactions TO reads the value of X again and it is changed by another transaction
T1 between the two reads. Transaction TO and TI read the same value.
iii. Ovenwriting uncommitted Data (WW conflicts): A transaction T1 could overwrite
the value of an object X, which has already been modified by a transaction TO,
while TO is still in progress. Even if T1 does not read the value of X written by TO.
For example, Suppose that Deepak and Sourabh are two employees and their
salaries must be equal. Transaction TO set to salaries to Rs. 2000 and TI set to
salaries Rs, 3000. If we execute serially in the serial order TO followed by T1 both
receive Rs. 3000, the serial order Tl followed TO both receive Rs. 2000, Notice that
neither transaction read a salary value before writing it such write is called blind
write. =
Schedule
A schedule is a list of actions (reading, writing, aborting,
committing) from a set of transactions and the order in which
two actions of transactions T appear in a schedule must be the
same as the order in which they appear in T.
Schedules represent sequential order in which instructions are executed in the system. $ schedule
of n transactions TO, TI, T2,..., Tn is an ordering of the operations of the transactions subject to
the constraint that for each transaction Ti that is in S, the operations of Ti in $ must appear in the
same order in which they occur in Ti. The operations of other transactions Tj can be interleaved
with the operations of Ti in S.
For example: Consider the simple banking system which has number of accounts and a set of
transactions that access and update those. accounts. Consider two transactions TO and TI which
transfer funds from one account to another, Transactions TO transfer Rs.200 from account P to
account Q. it is defined as,
Transaction T1 transfer 20 percent of the balance from account P to account Q. It is defined as,
Write (Q);3-8 / whan Relational Database
There are two types of schedule:
1, _ Serial Schedule: The transactions that are executed from start to end one by one is called
serial schedule. It consists of a sequence of instructions from various transactions where.
the instructions belonging to one single transactions appear together in that schedule.
‘Schedule 1: A serlal schedule TO followed by T1
Read (A);
Temp =A*0.2:
A=A-temp;
Schedule 2: A serial schedule T1 followed by TO
Schedule 2
B=B+ Temp;
Write (B);
Read (A);
A=A 200;
Write (A);
Read (8);
B=B +200;
Write (8);
2. Concurrent Schedule: When several transactions are executed concurrently the
corresponding schedule is called concurrent schedule.Transaction Management wfon\ 39
‘Schedule 3: A concurrent schedule
Schedule 3
TO
Read (A)
A=A-200
Write (A) Read (A)
Temp=A*0.2
A=A-Temp
Write (A)
Read ( B)
B=B+200
Write (B) Read (8)
B=B+Temp
Write (8)
Several execution sequences are possible. The schedule 3 will produce the same result as
schedule 1. But all concurrent executions may not result in a correct state.
5. Serializability
Serializability is the generally accepted criterion for correctness for the execution of a given set
of transaction. Transaction is considered to be correct if it is serializable i.e. it produce the same
result as some serial execution of the same transaction, running them one at a time,
A serializable schedule is called as given interleaved execution of a set of n transactions.
The following conditions hold for each transaction in the set:
1. All transactions are correct i.e. if any one of the transactions is executed by itself on a
consistent database, the resulting database will be consistent.
2. Any serial execution of the transactions is also correct and preserves the consistency of the
database.
There are two types Serializablity
1. Conflict Serializability
2. View Serializability3-10/ wien Relationaj Database
5.1 . Conflict Serializability
A schedule is conflict serializable if it is conflict equivalent to
some serial schedule. Every conflict serializable schedule is
serializable.
‘serializability
‘example.
Consider that TO and TI are two transactions and $ is schedule
for TO and T1.Ti and Ij are two instructions.
If Ti and Jj refer to different data items then li and Ij can be executed in any sequence. But if Ii
and Ij refer to same data items then the order of two instructions may matter.
Here Ii and Jj can be a read or write operation only. There are 4 conditions that need to be
considered.
1. Tis Read ( X) and Ij=Read (X).
The order of Ii and Ij does not matter because both are reading the data.
2. TieRead (X) and Ij=Write (X). If Ii come before Ij then Ti does not read the value of X
that is written by TI in Jj. If Ij comes before li the TO reads the value of X i.e. written by
T1.Thus order Ii and Ij matters.
3, TisWrite (X) and Ij=Read (X) The order of Ii and Jj matters for the same reasons in step 2.
4, _ lisWrite (X) and Ij=Write (X). If both are Write operations their order does not affect
either in TO or T1. But if next operation is Read (X) in S then the order is important. If
there is no operation after Ii and Ij in S then the order of li and Ij directly affects the final
value X in the database that results from schedule.
"We say that Ti and j conflict if they are operations by different transactions on the same data
item and at least one of these instructions is a Write operation.
Let us see the concept of conflict serializability with example of schedule 1. The Write (X)
instruction of TO conflicts with Read (X) instruction of T1. The Write (X) instruction of T1 does
not conflict with Read (Y) instruction of TI because they access different data items.Timenin Manajunett gala N41
Read (X)
Wate 6) Read (X)
Read (Y) Write (X)
Write (Y) Read (Y)
Schedule 2 is generated after swapping Write (X) instruction of T1 with Read (Y) instruction of
0.
In the same way we could swap:
1. Swap the Read (Y) instruction of TO with Read (X) instruction of T1.
2. Swap the Write (Y) instruction of TO with Write (X) instruction of T1.
3. Swap the Write (Y) instruction of TO with Read (X) instruction of T1.
‘The Final Result of these Swaps is shown as Schedule S'.
Read (x)
Write (x)
Read (Y)
Write (Y)
If a schedule S can be transformed into a schedule S' by a series of Swaps of non-conflicting
instructions. We call S and S' are Conflict equivalent.
Testing for Conflict Serializability
To check conflict serializablity is to draw a precedence graph for given schedule and if the cycle
is not present in the schedule then we can say that it is conflict serializable schedule.3-12/ Sian Relational Database
Precedence graph contain vertices, that is, transactions present in schedule and edges are
conflicting instructions in transactions.
Algorithm can be used to test a schedule for conflict serializability. The algorithm looks at only
read and write operations in a schedule to a construct precedence graph (or serialization graph)
which is directed graph G=(N,E) that consists of a set of nodes N={ TO,TI,....Tn} and a set of
Algorithm: Testing conflict serializability of a schedule S
1. . For each transaction Ti participating in schedule S, create a node labeled Ti in the
precedence graph.
2. For each case in $ where Tj executes a read (X) after Ti executes a write (X), create an
edge (Ti — Tj) in the precedence graph.
3. For each case in S where Tj executes a write (X) after Ti executes a read (X), create an
edge (Ti + Tj) in the precedence graph.
4. For each case in S where Tj executes a write (X) after Ti executes a write (X), create an
edge (Ti Tj) in the precedence graph.
5. The schedule S is serializable if and only if the precedence graph has no cycles.
For example: Consider following transactions
Read (X)
X=X+M
Write (X)
Precedence graph
‘A precedence graph, also named conflict graph and serializability graph, is used in the study of
database theory within the realm of computer science.
The precedence graph for a schedule S contains:
A node for each committed transaction in S.
ii, Amare from Ti to Tj if an action of Ti precedes and conflicts with one of Tj’s actions.Z\
Transaction Management wision \ 3-13
Use of precedence graph
It is used for checking deadlock. If cycle exists in a graph then there is deadlock in the system.
1. _ Serial schedule 1 transaction T0 followed by T1
Schedule 1
Wee
Read (X)
X=X-N
‘Write (X)
Read (Y)
Y=Y+N
Write (Y)
Read (x)
X=X+M
Write (x)
Precedence graph for serlal schedule 1
2. Serial schedule 2 transaction T1 followed by TO
Schedule 2
Read (X)
X=X+M
Write (X)
Read (x)
X=X-N
Write (x)
Read (Y)
Y=Y+N
Write (¥)
Precedence graph for serlal schedule 23-14/ukion Polationa Database
3. Non- serial schedule 3 transaction T0 followed by T1
Schedule 3
ees
Read (X)
X=X-N
Read (X)
X=X+M
Write (x)
Read (Y)
Write (%)
Y=Y+N
Write (Y)
Precedence graph for non-serial schedule 3 (not Serializable)
4. Non- serial schedule 4 transaction T0 followed by T1
‘Schedule 4
Read (X)
X=X+M
Write (X)
Read (Y)
Y=Y+N
Write (Y),
Precedence graph for non-serial schedule 4(Serializable)Transaction Management wien \ 315
5.2 View Serializability
A schedule $ is view serializability if it is view equivalent to a
serial schedule, Every conflict serializable schedule is also view
serializable but there are view serializable schedules that are not
conflict serializable.
Consider two schedules S and S'. The schedules $ and S* are said to be view equivalent if the
following three conditions hold’
1. For each data item X if transaction Ti reads the initial value of X in schedule S, then
transaction Ti must in schedule S' also read the initial value of Q.
2. Foreach data item X, if transaction Ti executes Read (A) in schedule S and that value was
produced by transaction, Ti must in schedule $’ also read the value of X that was
produced by transaction Tj. 7 .
3. For each data item X, the transaction that performs the final Write (X) operation in
schedule S must perform the final Write (X) operation in schedule S’.
A condition 1 and 2 ensures that same value is read in both the schedules. Condition 3 together
with 1 and 2 ensures that final result is same.
For example: Following schedule is a view serializable schedule
Write (x)
Write (x)
Write (X)
It is View Equivalent to the serial schedule since the Read (X) instructions reads
the initial value of X in both schedules and T2 performs the final write of X in both schedules.
In above example Transactions T1 and T2 perform Write (X) operations without having
performed a Read (X) operation. Write of this sort are called blind write. Blind write appear in
any view serializable schedule that is not conflict serializable.3.16/ when Relational Database
_ .
1. Consider the following transaction. Find out two
non-serial schedules serializable to serial schedule:
Read (A) Read (C) Read (B)
A=A+500 | Read () Read (C)
Write (A) B=B+C B=B+ 450
Read (B) Write (B) Write (B)
B=B-500 Read (A) C=C+B
Write (@) A=N-G Write (8)
Write (A)
Solution
Non-serial schedule 1:
A=A+500
Write (A)
Read (8)
B=B-500
Write (B)
Read (B)
Read (C)
B=B+450
Write(B)
Read (A)Non-serial schedule 2:
Read (C)
Read (B)
B=B+C
Write (B)
Read (B)
Read (C)
B=B+450
Write (B)
Read (A)
A=N-C
Write (A)
C=C+B
Write (B)
Read (B)
B=B-500
Write (B)
2. Consider the following transactions. Find out two
non-serial schedules that are serializable.
Read (x) Read (x)
x=x+1000 | x=x-1000
Write (x) Write (x)
Read (y), Read (y)
Read (z) y =y- 2000
y=y +2000 Write (y)
Write(y)
Z=z +3000
Write (2)3-18 / whan Relational Database
Solution
Non-serial schedule 1:
Non-serial schedule 2:
Read (x)
x=x+ 1000
Write (x)
Read (x)
x=x- 1000
Write (x)
Read (y)
Read (2)
y=y +2000
Write(y)
Read (y)
y= y-2000
Write (y)
z=z +3000
Write (2)
Read (x)
x=x- 1000
Write (x)
Read (x)
x=x+ 1000
Write (x)
Read (y)
y=y— 2000
Write (y)
Read (y)
Read (2)
y=y +2000
Write(y)
2=2 +3000
Write (2)
3. Consider the following transactions. Find out two
non-serial schedules that are serializable:
ae:
Read (Q)
P=P*10 Q=Q+10
Write (P) Write (Q)
Read (Q) Read (R)
Q=Q10 R=R"10
Write (Q) Write (R)Transaction Management won 3-19
Solution
Non-serial schedule 1:
[ast]
Read{(P)
P=P*10
Write(P)
Read(Q) .
Q=0+10
Write(Q)
Read (Q)
Q=Q/0
Write (Q)
Read (R)
R=R*10
Write (R)
Non-serial schedule 2;
Read(Q)
Q=0+10
write(Q)
Read(P)
P=P*10
Write(P)
Read (R)
R=R*10
Write (R)
Read ()
Q=Q10
Write (2)
4. Consider the following transactions: Find out two
non-serial schedules that are serializable:
Read (x) Read (x)
X= x+ 1000 x=x~- 1000
Write (x) Write (x)
Read (y) Read (y)
Read (2) y=y—2000
y=y+2000 | Write (y)
Write(y)
z=72+3000
Write (z)3-20/ wien Relational Datebase
Solution
Non-serial schedule 1:
iead (x)
x=x+ 1000
Write (x)
Read (x)
x= x= 1000
Write (x)
Read (y)
Read (z)
y=y +2000
Write(y)
Read (y)
y =y-2000
Write (y)
z=z+3000
Write (2)
Non-serial schedule 2:
Read (x)
x=X+ 1000
Write (x)
Read (y)
y=y~2000
‘Write (y)
Read (y)
Read (z)
y=y +2000
Write(y)
z= +3000
Write (z)
5.
Read (Z) Read (X)
Z=Z"10 Read (Z)
Write (2) X=X+Z
Read (Y) Write 0%)
Read (2)
Y=Y+Z
Write (¥)
Give two non-serial schedules that are serializable.Transaction Management vision \ 3-21
schedules S, and S; shown below can be the two non-serial schedules that are serializable to
given schedule
Read (X)
Read (Z)
Z=Z*10
Write (2)
Read (X)
Read (Z)
XeX4+Z
‘Write (X)
Read (Y)
Read (2)
Ya¥+Z
Write (Y)
»6. Consider the following transactions
Read (A) Read (8)
A=A‘S B=B'S
Write (A) Write (B)
Read (8) Read (A)
Read (C) AzA™10
[B=8"10 Write (A)
Write (B)
C=C*5
Write (0)
Give two non-serial schedules that are serializable.
Solution :
The schedules S; and S; shown below can be the two non-serial schedules that are serializable to
the given schedule.Read (A) Read (A)
A=zA*5 A=A‘S
Write (A) «Write (A)
Read (8) Read (8)
Read (C) Read (0)
B=B*10 B=B"10
Write (B) Write (B)
C=C'S Read (8)
Read (8) B=B'5
B=B‘S Write (B)
Wiite (8) Read (A)
Read (A) A=A*10
A=A"10 Write (A)
Write (C)
‘Write (A)
»7. Consider the foll
Read (2)
z=24+100
Write (2
Read (y)
y=y-100
Write
Give two non-serial schedules that are serializable.
Solution
The schedules $; and S shown below can be the two non-serial schedules that ate serializable to
the given schedule
Read(x)
z=2+100
Write (2)Transaction Management wien 3:23
8. Consider the following transactions:
ead (A)
[A = A-1000
Write (A) Write (A)
Read (8)
B= B+ 1000
Write (8)
Give two non-serial schedules that are serializable.
Solution
The schedules $; and S) shown below can be the two non-serial schedules that are serializable to
the given schedule
ie
Read (A)
A=A-1000
Write (A)
Read (A)
A=A+ 1000 A=A+ 1000
Write (A) Read (B)
Read (A) B=B+ 1000
B=B+ 1000 Write (B)
Write (B)
»9, Consider the following transaction. Find out two schedules serializable to serial
schedule
Solution
First we write serial schedule Serializable schedule 1
Read (X)
X=X+ 100
Write (X)
Read (¥)
Y=Y-100
Write (Y)
Read (2)
Read (Y)
YsY+Z
Write (Y)
Read (X)
X=N-Z
Write (X)
Read (2)Fieacwchunscageasne> Womaia RS
Serializable schedule 2
Read (X)
X=X+ 100
Write (X)
Read (Y)
Y=Y-100
Write (Y)
10. Consider the following transaction
a. Find out non-serial schedule, which is serializable to serial schedule
b. Find out non-serial schedule, which is serializable to serial schedule
<13, Tl, T2>.
Solution
First we write serial schedule Write (X)
Read (2)
Z=Z+10
Read (Y)
Ya¥+Z
Write (2)
Non-serial schedule for serial
Eat eS ease
Read (Z)
Z=Z+10
Read (Y)
Y=sY+Z
Write (2)
Read (X)
Write (Y)
Read (Y)
Y=sY-XTransaction Management usin \ 3-27
b. First we write serial scheiules <13,T1, T2>
ae
Read (Y)
YaY-X
Write (Y)
Read (X)
Read (Z
X=n+Z
Write (X)
Read (Z
Z=Z+10
Read (Y)
YaY+Z
Write (2)
Write (Y)
Non-serial schedule for serial
(ean E
Read (2)
Read (Z)
Z=Z+10
Read (Y)
Read (Y)
YaY-X
Write (Y) Ya¥+Z
Write (2)
Write (Y)
XeneZ
Write (%)
b>11. Consider the following Eran Give at least 2 serial schedules.
Read (A)
A=A -50 teA*O1
Write (A) AxAt
Read (B) Write (A)
B=B+50 Read (B)
Write (B) B=Bt
Write (8)
Solution
Suppose we consider Transaction TO followed by Transaction T1.2:28 / whas Relations! Database
Serial Schedule 1
210i
Read (A)
A=A-50
Write (A)
Read (8)
B=8+50
Write (B)
Read (A)
t=A‘O4
AzAt
Write (A)
Read (B)
B=B+t
Write (B)
Suppose we consider Transaction T1 followed by Transaction TO
‘Serial Schedule 2
LS
Read (A)
teAt04
AsAt
Write (A)
Read (8)
B=B+t
Write (8)
Read (A)
A=A-50
Write (A)
Read (B)
B=B+50
Write (8)
12. Consider the following transaction. Find out concurrent schedule, which is
serializable to serial schedule
Write (A)
Read (8)
B=B+50
Write (B)| Za\
Transaction Management wision \ 3-29
_ Solution
Following schedule is called as concurrent, which is serializable
Read (A)
A=A-50
‘Write (A)
Read ( A)
t=A‘01
AzAt
‘Write (A)
Read (B)
BeB+50
Write (B) Read (B)
B=But
Write (B)
»13. Consider following transactions. Give two Non-serial Schedules that are
serializable:
5 Te
Read(X) Read(Y)
X=X-4000 Y=¥+5000
Write(X) Write(Y)
Read(Y) Read(Z)
Y=Y+1000 2=Z+5000
Write(Y) Write(Z)
Solution
Read(x)
X=X-1000
Writer)
Read(Y)
Y=Y+5000
Write(Y)
Read(Y)
Y=Y+1000
Write(Y)
Read(Z)
2245000
Write(Z)3-30/ white Relational Database
Read(X)
X=X-1000
Write(x)
Read(Y)
Y=¥+5000
WriterY)
Read(Z)
2=2+5000
Write(Z)
Read(Y)
Y=¥+1000
Write(y)
14. Consider the following Transactions. Give two Non-serial schedules that are
serializable:
eta)
Read(x) | Read(Y)
XeX+10 | YeY-10
Write(x) | WritecY)
Read(Y) | Read(Z)
Y=¥+20 | Z=Z-20
Writer) | Write(2)
ReadiZ)
2=2+30
Write(Z)
Solution
Following are the two schedules which are serializable.
a]
Read(X)
XeX+10
Writer)
Read()
YeY-10
Write(Y)
Read(Y)
YaY+20
Write(Y)
Read(Z)
Z=2-20
Write(Z)Read(x)
XeX+H10
Write(X)
Read(Y)
Y=Y-10
Read(Y)
Y=Y420
Write(y)
Read(Z)
222430
Write(2)
o>
Transaction Management wision \ 3-31
»15. Consider the following Non-serial Schedule
Read(X)
X:=X-N
Read(X)
X=X+N
Write(x)
Read(Y)
Write(X)
Is the schedule serializable to a serial schedule ?
Solution
a.
First we draw serial schedule T1, T2
ReadX)
XeX-N
write(%)
Read(Y)
Y=Y+N
Write(Y)
Read(x)
X=X+N
Write(X)
In the given non serial schedule Read(X) of T2 reads the original value of X where in
serial schedule read(X) of T2 reads the value updated by Write(X) of T1. Thus
the order of conflicting instructions is not same in both the schedules, Thus, the given non
serial schedule is not serializable.Do
3-32/ wsion Relational Database
ji, We can draw precedence graph for given non serial schedule. There exists
graph so given non serial schedule is not serializable.
16.
Consider the following transaction.
we
Read(A)
A:=A-70
Write (A)
Read{(B)
B:=B+70
Write(B)
Give at least two serial schedules.
Solution
Non serial schedule S,:
Non serial schedule S:
ReadtA)
A=A-70
‘Write(A)
Read(B)
B=B+70
Write(B)
rc
Read(A)
A=A-70
‘Write(A)
Read(B)
B=B+70
Write(B)
Read(A)
teAt04
AsA-t
Write (A)
Read(B)
B=B+t
Write(B)
Read(A)
t=A°0.1
AzAt
Write(A)
Read(B)
B=B+t
Write(B)
Read(A)
A=At
Write(A)
Read(B)
B=B+t
Write(B)Transaction Management wken\ 3-33
17. Consider the following transactions. Find out two concurrent schedule, which will
be serializable to serial schedule :
B= B+ 10
Write (B)
Read (C)
C=C +50
Write (C)
Solution
The schedules S, and S shown below can be 2 non serial schedules that are serializable to given
schedule.
Following is schedule S,
Read (A) "
Ais A-70
Write (A)
Read (B)
B= B+10
Write (B)
Read (8)
B= B+70
Read (C)
C=C +50
Write (C)
Following is schedule S,
Read (B)
B:=B+ 10
Write (B)
Read (C)
Crm C+ 50
Write (C)3-34/usan Relational Database
»»18. Consider the following transaction. Give two non serial schedules that are
serializable.
ReadiA) Read(x)
AzAsS X=X-10
Write(A) Write(x) :
Read(B) Read(B)
Read(C) B=B-20
B=B+10 Write(B)
Write(B)
C=C+15
Write(C)
Solution
The schedules S1 and S2 shown below can be 2 non serial schedules that are serializable to
given schedule.
Following is schedule S,:
Read(X)
X=X-10
Write(X)
Read(B)
B=B-20
Write(B)
Read(A)
AnAsS
Write(A)
Read{(B)
Read(C)
BaB+10
Write(B)
C=C+15
Write()
Following is schedule S;: s
a 72
ReadiA)
AcAsS
Write(A)
Read(X)
X=X-10
‘Write(x)
Read(B)
Read(C)
B=B+10
Write(B)
Read(B)
B=B-20
Write(B)
CaCH15,
Write(C)Transaction Management wien \ 3-35
19. Consider the following transaction. Find out a non serial schedule which is
serializable to serial schedule
Solution
‘Non serial schedule S,:
Read(Y)
Write(Y)
Non serial schedule S3:
Read(X)
»»20. Consider the following transaction. Give two non-serial schedules that are
serializable.3-36/ vision Relational Database
Solution
Segond schedule S2
z
read (8) read (x)
x=X-m x=x-m
write (x) write (x)
read (x) read (x)
x=x4n X=x+n
write (x) read (y)
read (y) y=y+m
y=y+m write (y)
write (y) os write (x)
»21. Consider the following transaction. = out a non serial schedule which is
serializable to serial schedule are as
follows.
read(x) read(x) | read(z)
x=x+100 x=x+100
write(x) write(x)
read(z) readly)
read(x) y=y-100
XeXZ write(z)
write(x) read(y)
readly) yeysz
yey-100 write(y)
write(z) read(y)
readily) read(z)
yeysz y=y+50
write(y) write(y)
ready) read(x)
read(z) XeXZ
yey+50 z=z+y
write(y) write(2)
zeny writa(x)
write(2)‘Transaction Management Sian \, 3-37
22. Consider the following transactions.
Give two non serial schedules that are serializable.
Solution
Read(x)
x=x+ 1000
Write(x)
Read(y)
y=y~500
Write(y)
Readly)
y=y+ 1000
Writely)
Read(z)
z=z-500
Write]
Read(x)
x=x+ 1000
Write(x)
Read(y)
y=y~500
Write(y)
Read(z)
z=2-500
Write(2)
Ready)
y=y+ 1000
Write(2)
23. Consider the following transactions.
Read (2 Z= 2+ 100
X=X4z
Write(x) Read(y)
y=y¥+200
Write(y)
Give two non serial schedules that are serializable.Solution
z=2+100
‘Write(z)
Read{y)
y=y+200
White (y)
Exercise
1. Whatis transaction? State operations performed on transaction.
2. Define: i, commit ii, Rollback
3, Whatis serializability? List the types of serializability.
4. What is schedule? Give types of schedule.
5. Whatis a precedence graph?
6. What is Transaction? List Properties of Transaction.
7. What is Serializability?
8. List the states of transaction.
9. Consider the following transactions, Find out tow non-serial schedules that are
serializable.
ee Te
Read (x) Read (2)
x=x+10 Read (y)
Write (x) y=y-z
Read (y) _ Write (y) |
y=y-10 Read (x)
Write (y) X=X42
Write (x)Transaction Management when\ 3-39
Consider the following non-serial schedules. Is this schedule serializable?
Write (A)
Read (A)
-
‘Write (A)
Explain various states of transaction in detail.
What is Schedule? Explain types of schedule with example.
What are the various problems that occur in concurrent transaction?
What is transaction? Explain ACID properties of transaction.
Consider the following transactions. Give two non-serial schedules that are serializable.
Para
Read (A) | Read (C)
A= A+ 100 | Read (B)
‘Write (A) B=B+C
Read (B) Write (8)
B= B+ 100 | Read (A)
‘A= A—C | Write (C)
‘Write (A)
Consider the following
transactions. Give two non-serial schedules that are serializable.
Read (C)_| Read (B)
A=A+ 100 | Read (8) | B=B + 200
‘Write (A) B=B+C | Write (B)
Read (B) Write (B)_| Read (C)
B= 8+ 100 | Read (A) | C=C +200
Write (B) | A=A-C ae
‘Write (A)
Consider the following transactions, Give two non-serial schedules that are serializable.
Maes
Read (A) | Read (A)
‘A=A+ 1000 | A=A~ 1000
‘Write (A) | Write (A)
Read (BC) | Read (B)
C= C-1000 | B=B8— 1000
Write (6) | Write (B)
Read (B)
B= B+ 1000
Write (B)3.40 / usion Relational Database
21.
Explain ACID properties of transaction in detail.
Consider the following transactions.
Give two non serial schedules that are serializable.
Consider the following transactions.
oma Lee
Read(x)
Read (z) | z= z+ 100
X= x42 | Write(z)
Write(x) | Readiy)
Give two non serial schedules that are serializable.
Consider following the transactions. Give two Non-serial Schedules that are serializable:
Read(x)__| Read(¥)
X=X-1000_| Y=¥+5000
Write) | Write(¥)
Read| Read(Z)
Y=Y+1000 | Z=Z+5000
Write(y) [Write
Consider the following Transactions. Give two Non-serial schedules that are serializable:
ar
Read(X)
XeX+10 | Y=Y-10
Write(x) | Write(Y)
Read(Y) | Read(Z)
Ya¥+20 | 2=2-20
Write(Y) | Write(Z)
Read(Z)
222+30
Write(Z)BR
27.
Transaction Management wkan\ Sat
Consider the following Non-setial Schedule
ReadiX)
Xi=X-N
Read(X)
XeX+N
‘Write(X)
Read(Y)
Write(x)
Yi=Y+N
Write(Y)
Is the schedule serializable to a serial schedule ?
Consider the following transaction.
X Read(A)
A:=A-70
Write (A)
Give atleast two serial schedules.
Explain different types of Failure.
Consider the following transactions. Find out two concurrent schedule, which will be
serializable to serial schedule :
What is transaction? Explain states of transaction with diagram.
Explain concurrent execution of transaction with example and advantages of concurrent
execution.42/ when Relational Database
Questions asked in Previous Exams
1. Define transaction. [oct, 2018]
2. Whatis schedule? List the types of schedule. [Oct. 18, Apr. 18]
3. _List the state of Transaction. (Oct. 201
4. What is transaction? List properties of transaction. (Apr. 2017)
1. Explain the properties of transaction. [Oct. 2018]
2. Whatis serializability? Explain types with example. ct. 204;
3. Consider the following transaction. Find out two non-serial schedules serializable to serial
schedule: (Oct. 2018}
Tt 12 eas
Read (A) Read (C) Read (B)
A= A+ 500 Read (8) Read (C)
Write (A) B=B+C B=B+ 450
Read (B) Write (8) Write (6)
B =B-500 Read (A) C=C+B
Write (8) A=N-GC Write (8) —
Write (A)
4. Consider the following transactions. Find out two non-serial schedules that are
serializable: [Oct 2018]
Ti Tz
Read (x) Read (x) _
X=Xx+ 1000 x= x= 1000
Write (x)
Read (y)
Read (z)
y= y +2000
Write(y)
z= z+ 3000
‘Write (2)
5. Whatis transaction? Explain the states of transaction with the help of diagram.[Apr. 2018]
Consider the following transactions. Find out two non-serial schedules that are
serializable: [Apr. 2018]
roy E 72
Read (P) Read (Q)
P=P*i0 Q=0+10
‘Write (P) Write (Q)
Read (Q) Read (R)
Q= 10 R=R*10
Write (Q) [Write (R)ul.
a
Transaction Management wken\ $43
Consider the following transactions: Find out two non-serial schedules that =
serializable: (Apr. 2018)
Read (x) _
x=Xx+ 1000
Write (x)
Read (y)
Read (z)
yey +2000
Write(y)
z=2z+ 3000
‘Write (2)
What is transaction? Explain properties of transaction. [Qct. 2017]
What are the problems in concurrent execution of transaction? [Qct. 2017]
What is serializability? Explain conflict serializability with example. [Oct. 2017]
Consider the following transactions. [Oct. 2017]
Read (Z) Read (X)
Z=Z*10 Read (Z)
‘Write (Z) X=X+Z
Read (Y) Write (X)
Read (Z)
VeV+z
Write (Y)
Give two non-serial schedules that are serializable.
Consider the following transactions: [Oct 2017]
Read (A) Read (8)
AzA‘S B=B°S
Write (A) Write (8)
Read (8) Read (A)
Read (C) A=A?i0
B=8*10 | Write (A)
‘Write (B)
C=C"S
Write (C)
Give two non-serial schedules that are serializable.
Explain states of transaction with the help of suitable diagram. [Apr 20171
What is serializability? Explain view serializability with example. [Apr. 2017]3-44 / wien Relational Database
15. Consider the following transactions.
TH 2
Read (z) Read (x)
Z=z+100 Read (y)
Write (2) ysy-x
Read (y) Write (y)
y=y—100
Write (7)
Give two non-serial schedules that are serializable.
16. Consider the following transactions:
jee ae
Read (A) Read (A)
A=A+1000 | A=A-1000
Write (A) Write (A)
Read (B)
8 =B + 1000
Write (B)
Give two non-serial schedules that are serializable.
(a
vision
rt. 201