0% found this document useful (0 votes)
14 views59 pages

Unit IV Transaction

Uploaded by

dhyanimishti12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views59 pages

Unit IV Transaction

Uploaded by

dhyanimishti12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

h a n g e Pro h a n g e Pro

XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Quality Content for Outcome based Learning

Transaction
Unit-4

Ver. No.: 1.1 Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Introduction
In general terms, a transaction can be defined as a logically related group of operations. A single
operation is the minimum processing unit that cannot be divided further.

Example 1:A teacher is marking the attendance of a student in the attendance system. The set of
operations would be like this:
1. Read the attendance record balance of a student of a subject.
2. Add the new attendance value to the attendance balance.
3. Write the newly updated attendance balance to the attendance record.

Example 2: A parent is transferring money from his bank account to a university bank account. The
set of operations would be like this:
1. Read parent’s account balance.
2. Deduct the amount from the parent's account balance
3. Write the remaining balance to the parent's account
4. Read university bank account balance
5. Add the amount to the university bank account balance
6. Write the newly updated balance to the university bank account

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Introduction (Cont…)
In the above examples, all the operations are logically related for a
defined purpose and any operation cannot be further subdivided into
further sub-operations.

Thus, in example 1, “marking attendance of a student by a teacher” is


one transaction and in example 2, “transferring money from parent’s
account to university account” is also one transaction.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Transaction in DBMS
 In terms of DBMS, a transaction is the execution of a program, a sequence of operations that
accesses or updates the contents of a database.

 A transaction is a logical, atomic unit of work that contains one or more SQL statements.

 The database operations that form a transaction can be embedded within an application
program or specified interactively via a high-level query language such as SQL.

 The actions accomplished in a transaction contain one or multiple database actions such as
retrieve, insert, or update data.

 A transaction on the database is either completed in its entirety or not done at all. If the
database was in a consistent state before a transaction, then after execution of the
transaction, the database must be in a consistent state.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Transaction in DBMS (Cont…)


Data Item: A database is represented as a collection of named data items. A data item can be a
database record, a larger unit such as a whole disk block, or even a smaller unit such as an
individual field (attribute) value of some record in the database.

 The data is accessed by transactions using two operations.


 read(X): This operation reads the value of data item X from the database server and keeps it in a
buffer in the main memory, as shown in Figure 7.1

Read Operation : read(X)

5000 Buffer (X) Figure 7.1: Read Operation


Input
5000 Block (X)

Main Memory
Disk

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Transaction in DBMS (Cont…)


 write(X): This operation writes the value of data item X to the database server from the buffer
as shown in Figure 7.2
Write Operation : write(X)

7000 Buffer (X)

Output Figure 7.2: Write Operation


7000 Block (X)

Main Memory
Disk

 Block movements between disk and main memory are initiated through the following two
operations:
 Input(B) transfers the physical block B to the main memory
 Output(B) transfers the buffer block B to the disk and replaces the appropriate physical
block there.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Transaction in DBMS (Cont…)


 Buffer: A buffer is a region of the main memory storage used to store data temporarily

 Using our simple model, we write the above example like this:
 In example 1, let's say the attendance record of a student is X; the steps of the transaction are:
 1. read (X); (Retrieve the student attendance record X)
 2. X = X + 2; (Adding the attendance value 2 to the attendance record)
 3. write (X); (Updating the attendance value in student record X)

 In example 2, your parent's account is A and your university account is B. You are transferring Rs. 50000
from A to B, the steps of the transaction are:
 1. read (A); (Retrieve the value of parent’s account A)
 2. A = A - 50000; (Deduct the amount Rs. 50000 from parent’s account A)
 3. write (A); (Updating the remaining balance to parent’s account A)
 4. read (B); (Retrieve the value of university account B)
 5. B = B + 50000; (Add the amount Rs. 50000 from parent’s account A)
 6. write (B); (Updating the remaining balance to parent’s account A)

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Transactions States and various operations


 A transaction may be in many states during its lifetime. States of the transaction are the
situation and condition in which a transaction in DBMS is currently present. A particular
transaction can only be in one state at any given time. This transaction state helps us know about
the present situation in which the transaction is executing and will suggest the system and
possible further states. The various operations performed by the transaction are mentioned
below:

 BEGIN TRANSACTION. This marks the beginning of transaction execution.


 READ or WRITE. These specify read or write operations on the database items that are executed
as part of a transaction.
 END TRANSACTION. This specifies that READ and WRITE transaction operations have ended
and marks the end of transaction execution.
 COMMIT. This signals a successful end of the transaction so that any changes (updates)
executed by the transaction can be safely committed to the database and will not be undone.
 ROLLBACK (or ABORT). This signals that the transaction has ended unsuccessfully so that any
changes or effects that the transaction may have applied to the database must be undone.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Transactions States and various operations


The following Figure 7.3 shows the state transition diagram, which shows how a transaction
moves through its execution states along with the operations:

Figure 7.3: Representation of Operations and States of a Transaction

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Transactions States and various operations


 Active State
 The active state is the initial state, and a transaction is in it as soon as it begins. If a
transaction is in execution, it is said to be in an active state. A transaction contains the
number of read and write operations. All the Read and Write operations are executed by
transaction in this state. All the read and write operations are performed on the main
memory (local memory) instead of the actual database during this state.

 Partially Committed State


 After completing the various operations in Active State, when a transaction ends, it
moves in a partially committed state. In this state, some types of concurrency control
protocols and recovery protocols (to be discussed later in the chapter) may do additional
checks on the read-write operations performed in Active State to see if the transaction
can be committed or not and a system failure will not result in an inability to record the
changes of the transaction permanently.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Transactions States and various operations


 Committed State
 If a transaction completes the execution successfully, the checks performed in a partially
committed state are successful, the transaction is entered into Committed State. In this state, all
the changes maintained in the local memory during a partially committed state are permanently
stored in the database.

 Failed State
 If a transaction is executing and a failure occurs, either a hardware failure or a software failure,
the transaction is aborted from the active state or partially committed state and moves into a
failed state. Also, transactions are moved to this state if any consistency checks performed in a
partially committed state fail.

 Terminated State
 Either the transaction comes from a “failed state" after rollback or the transaction comes from the
"committed state". Then, the system is consistent and ready for a new transaction and the old
transaction is terminated.
Copyright © 2021, ABES Engineering College
h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

ACID Properties
 ACID is a concept (and an acronym) that refers to the four properties of a transaction in a
database system:
A - Atomicity
C - Consistency
I - Isolation
D - Durability

 These properties ensure the accuracy and integrity of the data in the database, ensuring that
the data does not become corrupt due to some failure, guaranteeing the validity of the data even
when errors or failures occur.

 The ACID properties allow us to write applications without considering the complexity of the
environment where the application is executed. These are essential for processing transactions in
databases. Because of the ACID properties, we can focus on the application logic instead of
failures, recovery, and data sync.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Atomicity
 In the context of databases, atomicity means that either:
 The execution of the transaction got completed and committed.
 No transaction at all means transaction is aborted.

 A transaction must be an atomic unit of work, which means that all the modified
data are performed, or none of them will be. The transaction should be executed
completely or fail. If one part of the transaction fails, all the transactions will fail.
Therefore, the transaction should not occur partially.

 In the above-mentioned example 2, let suppose parent account A has Rs. 70000
in his account from which he needs to send Rs. 50000 to university account B. In
account B, a sum of Rs. 100000 is already present. When Rs. 50000 is
transferred to account B, the sum will become Rs. 150000.
Copyright © 2021, ABES Engineering College
h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Atomicity (Cont…)
 In this transaction, there will be two operations that will take place to complete this transaction.
 The amount of Rs.50000 that the parent wants to transfer will be debited from his account A
 The same amount will get credited to college account B.

 During the transaction, suppose the first operation of debit executes successfully, but the credit
operation fails. Thus, in parent account A, the value becomes Rs. 20000, and to that of college
account, it remains Rs. 10000 as it was previously present as shown in Figure 7. 4

Figure 7.4: Representation of a Fail Transaction

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Consistency
 A transaction should be consistency preserving, meaning that if it is completely executed
from beginning to end without interference from other transactions, it should take the
database from one consistent state to another.

 In the above example, Account A and Account B have Rs. 100000 and Rs. 70000
respectively. So, the total amount is Rs. 100000+ Rs. 70000, i.e., Rs. 170000 before the
transaction. When any transaction is executed, then the total amount should also be Rs.
170000. If the transaction occurs, then Rs. 50000 will be deducted from Account A and
added to Account B. The total amount after the transaction will be Rs. 20000 + Rs.
150000 = Rs. 170000. So, this property ensures the consistency of the database.

 Another way of ensuring consistency within a database throughout each transaction is


by enforcing integrity constraints placed on the database. For example, integrity
constraint is defined as "accounts must have a positive balance". Therefore, if a
transaction brought any account into a negative balance, that transaction would be rolled
back.
Copyright © 2021, ABES Engineering College
h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Isolation
 This property tells us that a transaction should appear as though it is being executed in isolation
from other transactions, even though many transactions are executed concurrently. This means, if
more than one transaction is taking place in parallel, then the occurrence of one transaction will
not affect the other transaction. If any transaction is using a data item, then it can't be used by
other transactions until the first transaction ends.
 Example: Suppose we have two transactions, T1 and T2, which are defined as follows.
 In transaction T1, a parent is transferring an amount of Rs. 50000 from account A to university
account B. The initial balance of account A is Rs. 70000.
 In transaction T2, the bank is adding the interest of 10% in account A.

Figure 7.5: Representation of two parallel


executing transactions

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Isolation (Cont…)
 Now, consider a situation where T1 has been executed until A=A-50000 and then T2 starts. Due
to this, transaction T2 reads the incorrect value of A. It reads the value as 70000 and the
operations which should have been performed by taking the value as 20000, T2 will perform by
taking the value as 70000 as shown inFigure 7. 5.This leads to inconsistent results. For example,
the output of the transaction T2 should have been 20000 *.1 =2000, but it will produce the output
as 70000*.1 =7000 as T2 has read the incorrect value of A. This problem happened because the
transaction result of T1 was made available for T2. So to avoid any such problem, the
transactions take place in isolation.

 Importantly, this doesn't mean two operations can't happen at the same time. On the contrary,
multiple transactions can occur as long as those transactions have no possibility of impacting the
other transactions simultaneously.

 Doing this can impact the speed of transactions as it may force many operations to wait before
they can initiate. However, this tradeoff is worth the added data security provided by isolation.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Durability
 Durability ensures that changes made to the database (transactions) that are
successfully committed will survive permanently, even in the case of system
failures.

 This ensures that the data within the database will not be corrupted by:
Service outages
Crashes
Other causes of failure

 For example, in an application that transfers funds from one account to another,
the durability property ensures that the changes made to each account will not be
reversed.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Concept of Concurrency
 The database system can be classified according to the number of users who can use
the system concurrently. A DBMS is a single-user if at most one user can use the
system, and it is a multi-user if many users can use the system simultaneously. This
means the computer runs multiple transactions (programs) at the same time.

 For example, an airline reservations system is used by hundreds of travel agents and
reservation clerks concurrently. Systems in banks, insurance agencies, stock exchanges
and the like are also operated by many users who submit transactions concurrently to
the system.

 In a single-user database, the user can modify data in the database without concern for
other users modifying the same data at the same time. However, in a multi-user
database, the statements within multiple simultaneous transactions can update the
same data.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Concept of Concurrency (Cont…)


 When multiple transactions are trying to execute simultaneously, then there can be two
possible ways:
 Serial or Sequential Execution of Transactions
 Non-serial or Concurrent Execution of Transactions

 Let understand the above-mentioned possible ways with the help of an example.

 Suppose there are two students, S1 and S2, who are submitting their fees to college at the
same time (using web/mobile application). S1 is submitting Rs. 2000 in college account (X)
and S2 is submitting Rs. 3000 in college account (X). Assume they have already submitted
Rs. 5000 and Rs. 10000 in the college account. Now there are two transactions T1 and T2,
T1 transaction contains the operations of fee submitting by student S1, and the T2
transaction contains the operations of fee submitting by student S2. Both transactions, T1
and T2, are executing at the same time means executing simultaneously.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Concept of Concurrency (Cont…)


In Serial/Sequential Execution, if transaction T1 will execute, transaction T2 has to wait till T1
complete its all operation as in Table 7. 1 And if transaction T2 will execute, transaction T1 has to
wait till T2 completes its all operation as in Table 7. 2

Table 7. 1: Serial or Sequential Execution of Transaction


Timestamp T1 T2 Remarks

1 read(X) T1 read X : 5000


2 X = X + 2000 Computed : X = 7000
3 write(X) T1 write X as 7000 in Temp buffer
4 Commit T1 update X : 7000 in database
5 read(X) T2 read X : 10000
6 X = X + 3000 Computed : X = 13000
7 write(X) T2 write Y : 13000 in Temp buffer
8 Commit T2 update Y : 13000 in database

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Concept of Concurrency (Cont…)


Table 7. 2: Serial or Sequential Execution of Transaction

Timestamp T1 T2 Remarks

1 read(X) T2 read X : 10000


2 X = X + 3000 Computed : X = 13000
3 write(X) T2 write X as 13000 in Temp. buffer
4 Commit T2 update X : 13000 in database
5 read(X) T1 read X : 5000
6 X = X + 2000 Computed : X = 7000
7 write(X) T1 write X : 7000 in Temp. buffer
8 Commit T1 update X : 7000 in database

With the help of the above example, when multiple transactions are trying to execute at the same
time in serial or sequential order of execution, we can say that database will be 100 % consistent.
However, this approach of serial execution creates some serious issues like waiting time of other
transactions will increase, the response time of other transactions is increased, resource
utilization is less and in summary, system performance will be very poor.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Concept of Concurrency (Cont…)


To overcome these problems, we add the concept of concurrency and we use
concurrent execution of transactions. In this approach, each transaction gets a
small time slot to complete its operation in a cyclic manner, meaning the
transactions' operations are interleaved with respect to time.

Interleaving of operations: As there is only one CPU, only one program can be
2200321530021
processed. To avoid excessive delays, concurrent systems execute some
operations from one transaction, then suspend that transaction and execute some
operations from the next transaction, and so on. A transaction is resumed at the
point where it was suspended when it gets its turn to use the CPU again. This is
known as interleaving.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Concept of Concurrency (Cont…)


Here few possible concurrent executions of the above-mentioned example are shown below.
Timestamp T1 T2

1 read(X)
2 read(X)
3 X = X + 2000
Table 7. 3: Example-1 of Concurrency 4 X = X + 3000
5 write(X)
6 write(Y)
7 Commit
8 Commit

Timestamp T1 T2

1 read(X)
2 X = X + 3000
3 read(X)
Table 7. 4: Example-2 of Concurrency 4 X = X + 2000
5 write(X)
6 write(X)
7 Commit
8 Commit

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Concept of Concurrency (Cont…)


Timestamp T1 T2

1 read(X)
2 X = X + 2000
3 read(X)
Table 7. 5: Example-3 of Concurrency 4 X = X + 3000
5 write(X)
6 write(X)
7 Commit
8 Commit

Timestamp T1 T2

1 read(X)
2 X = X + 2000
Table 7. 6: Example-4 of Concurrency 3 write(X)
4 read(X)
5 X = X + 3000
6 write(X)
7 Commit
8 Commit

In all the above-mentioned examples, various operations of the transactions T1 and T2 are
interleaved.
Copyright © 2021, ABES Engineering College
h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Concept of Concurrency (Cont…)


 Using Concurrency or Concurrent Execution, we can achieve the following things –
 Low waiting time
 Low Response time
 High Resource Utilization
 High System performance

 The problem with concurrency is the high risk of database inconsistency. This property of
DBMS allows many transactions to access the same database at the same time without
interfering with each other. The primary goal of concurrency control is to ensure the atomicity of
the execution of transactions in a multi-user database environment.

 Concurrency controls mechanisms attempt to interleave READ and WRITE operations of


multiple transactions in such a manner that the interleaved execution yields identical results to the
results of serial execution. Due to uncontrolled concurrency, a few inconsistency problems
may create an inconsistent database state, which is mentioned below.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Schedules

 Schedule – a sequences of instructions that specify


the chronological order in which instructions of
concurrent transactions are executed
 A schedule for a set of transactions must consist of all instructions
of those transactions
 Must preserve the order in which the instructions appear in each
individual transaction.
 A transaction that successfully completes its
execution will have a commit instructions as the last
statement
 By default transaction assumed to execute commit instruction as its
last step
 A transaction that fails to successfully complete its
execution will have an abort instruction as the last
statement
Copyright © 2021, ABES Engineering College
h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Schedule 1

 Let T1 transfer $50 from A to B, and T2 transfer 10%


of the balance from A to B.
 A serial schedule in which T1 is followed by T2 :

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Schedule 2
 A serial schedule where T2 is followed by T1

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Schedule 3

 Let T1 and T2 be the transactions defined previously.


The following schedule is not a serial schedule, but it
is equivalent to Schedule 1

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Schedule 4

 The following concurrent schedule does not preserve


the value of (A + B ).

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Serializability

 Basic Assumption – Each transaction preserves


database consistency.
 Thus, serial execution of a set of transactions
preserves database consistency.
 A (possibly concurrent) schedule is serializable if it is
equivalent to a serial schedule. Different forms of
schedule equivalence give rise to the notions of:
1. Conflict serializability
2. View serializability

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Simplified view of transactions

 We ignore operations other than read and write


instructions
 We assume that transactions may perform arbitrary
computations on data in local buffers in between
reads and writes.
 Our simplified schedules consist of only read and
write instructions.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Conflicting Instructions

 Instructions li and lj of transactions Ti and Tj


respectively, conflict if and only if there exists some
item Q accessed by both li and lj, and at least one of
these instructions wrote Q.
1. li = read(Q), lj = read(Q). li and lj don’t conflict.
2. li = read(Q), lj = write(Q). They conflict.
3. li = write(Q), lj = read(Q). They conflict
4. li = write(Q), lj = write(Q). They conflict
 Intuitively, a conflict between li and lj forces a (logical)
temporal order between them.
 If li and lj are consecutive in a schedule and they do
not conflict, their results would remain the same even
if they had been interchanged in the schedule.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Conflict Serializability

 If a schedule S can be transformed into a schedule S’


by a series of swaps of non-conflicting instructions,
we say that S and S’ are conflict equivalent.
 We say that a schedule S is conflict serializable if it
is conflict equivalent to a serial schedule

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Conflict Serializability (Cont.)

 Schedule 3 can be transformed into Schedule 6, a serial


schedule where T2 follows T1, by series of swaps of non-
conflicting instructions. Therefore Schedule 3 is conflict
serializable.

Schedule 3 Schedule 6

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Conflict Serializability (Cont.)

 Example of a schedule that is not conflict


serializable:

 We are unable to swap instructions in the above


schedule to obtain either the serial schedule < T3, T4
>, or the serial schedule < T4, T3 >.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

View Serializability

 Let S and S’ be two schedules with the same set of


transactions. S and S’ are view equivalent if the
following three conditions are met, for each data item
Q,
1. If in schedule S, transaction Ti reads the initial value of Q, then in
schedule S’ also transaction Ti must read the initial value of Q.
2. If in schedule S transaction Ti executes read(Q), and that value was
produced by transaction Tj (if any), then in schedule S’ also
transaction Ti must read the value of Q that was produced by the
same write(Q) operation of transaction Tj .
3. The transaction (if any) that performs the final write(Q) operation in
schedule S must also perform the final write(Q) operation in
schedule S’.
 As can be seen, view equivalence is also based
purely on reads and writes alone.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

View Serializability (Cont.)

 A schedule S is view serializable if it is view


equivalent to a serial schedule.
 Every conflict serializable schedule is also view
serializable.
 Below is a schedule which is view-serializable but
not conflict serializable.

 What serial schedule is above equivalent to?


 Every view serializable schedule that is not conflict
serializable has blind writes.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Other Notions of Serializability

 The schedule below produces same outcome


as the serial schedule < T1, T5 >, yet is not
conflict equivalent or view equivalent to it.

 Determining such equivalence requires analysis


Copyright © 2021, ABES Engineering College
h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Testing for Serializability

 Consider some schedule of a set of transactions T1,


T2, ..., Tn
 Precedence graph — a direct graph where the
vertices are the transactions (names).
 We draw an arc from Ti to Tj if the two transaction
conflict, and Ti accessed the data item on which the
conflict arose earlier.
 We may label the arc by the item that was
accessed.
 Example of a precedence graph

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Testing for Serializability (Cont…)

Figure: Conditions to include an edge in


the precedence graph

 If the precedence graph for S has a cycle, then schedule S is not conflict
serializable. If the graph contains no cycles, then schedule S is conflict
serializable.

 A serializability order of the transactions can be obtained through topological


sorting, which determines a linear order consistent with the partial order of the
precedence graph. There are, in general, several possible linear orders that can
be obtained through topological sorting, as shown in Figure 7. 11.
Copyright © 2021, ABES Engineering College
h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Testing for Serializability


 When designing concurrency control schemes, we must show that schedules
generated by the scheme are serializable. We will now present a simple and efficient
method for determining the conflict serializability of a schedule. Consider a schedule
S. We construct a directed graph, called a precedence graph, from S.

 Precedence Graph Method: Conflict serializability of a concurrent schedule can be


tested using the precedence graph method. This graph consists of a pair G = (V, E),
where V is a set of vertices and E is a set of edges. The set of vertices consists of all
the transactions participating in the schedule.

 The set of edges consists of all edges Ti →Tj for which one of three conditions holds:
 1. Ti executes write(Q) before Tj executes read(Q).
 2. Ti executes read(Q) before Tj executes write(Q).
 3. Ti executes write(Q) before Tj executes write(Q).
Copyright © 2021, ABES Engineering College
h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Testing for Serializability (Cont…)

Figure 7.11: Illustration of topological sorting

Figure 7. 12 shows the precedence graphs for schedules 3 and 5 that do not
contain cycles. The precedence graph for schedule 9, on the other hand, contains a
cycle, indicating that this schedule is not conflict serializable.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Testing for Serializability (Cont…)

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Testing for Serializability (Cont…)

Figure 7. 12: Precedence graph


of a schedule with testing for
serializability

Topological Sorting: It is a special method to arrange the elements of a Directed Acyclic Graph
(DAG). It is used to design the scheduling applications where one job needs to be done before the
other.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Topological Sorting (Example)

Figure 7. 13: Illustration of topological sorting algorithm

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Test for View Serializability

 The precedence graph test for conflict serializability


cannot be used directly to test for view
serializability.
 Extension to test for view serializability has cost exponential in
the size of the precedence graph.
 The problem of checking if a schedule is view
serializable falls in the class of NP-complete
problems.
 Thus, existence of an efficient algorithm is extremely unlikely.
 However practical algorithms that just check some
sufficient conditions for view serializability can still
be used.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Recoverability (Cont…)
 It is important to design recoverable schedules. To achieve this, we need to place restrictions on
the type of schedules permitted in the system.

 The type of schedules acceptable from the viewpoint of recovery from transaction failure is:
 Recoverable schedule
 Cascadeless schedule
 Strict schedule

 Recoverable schedule: A recoverable schedule is one where, for each pair of transactions Ti
and Tj such that Tj reads a data item previously written by Ti, and the commit operation of Ti
appears before the commit operation of Tj.

 Table 7. 24 shows an example of a recoverable schedule where T2 reads the data item written by
T1 and the commit of T1 appears before the commit operation of T2 transactions. Hence, T2
reads the committed value of Q. If later T1 fails due to any reason, then no need to rollback the
dependent transaction T2.
Copyright © 2021, ABES Engineering College
h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Recoverable Schedules Example


Need to address the effect of transaction failures on concurrently
running transactions.

 Recoverable schedule — if a transaction Tj reads a


data item previously written by a transaction Ti , then
the commit operation of Ti appears before the
commit operation of Tj.
 The following schedule (Schedule 11) is not
recoverable

 If T8 should abort, T9 would have read (and possibly


shown to the user) an inconsistent database state.
Copyright © 2021, ABES Engineering College
h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Recoverability (Cont…)
Timestamp T1 T2 Remarks Before Execution Q=20
1 read(Q); F1 faculty readds Q=20
2 Q=Q+30; F1 faculty added his class count Q=20+30
3 write(Q); Now updated Q=50
4 read(Q); at timestamp 4, F2 faculty reads the uncommitted value Q as 50
5 Q=Q+35; Q is modfied to 75 Table 7.23: Irrecoverable schedule
6 write(Q); Q=75 updated on Stale storage/Disk
7 commit ; Faculty 2 committed his execution.
8 Fail Due to any reason Faculty1 action's fails. Uncommitted -->rollback & restart later
After Execution Q=75 which is incorrect

Now consider a situation where Faculty1 updated the count in data item Q about his/her class count
but forgot to make his/her action permanent using commit. After faculty 1, faculty2 updated his count
of attendees in Q and permanently updated his action doing commit at the end. Now, after some
time transaction of Faculty1, i.e., T1 gets failed due to any reason. Because changes are not
permanent, hence rollback occurs, but Q is 75 in the database (committed by faculty2). Such types
of schedules are irrecoverable, resulting in incorrect data.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Recoverability (Cont…)
Cascadeless schedule: A cascadeless schedule is one where, for each pair of transactions Ti and
Tj such that Tj reads a data item previously written by Ti, the commit operation of Ti appears before
the read operation of Tj as shown in Figure 7. 15. It is easy to verify that every cascadeless schedule
is also recoverable.

Figure 7.15: Examples of cascadeless schedule

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Cascadeless Schedules

 Cascadeless schedules — cascading rollbacks


cannot occur;
 For each pair of transactions Ti and Tj such that Tj reads a data
item previously written by Ti, the commit operation of Ti appears
before the read operation of Tj.
 Every Cascadeless schedule is also recoverable
 It is desirable to restrict the schedules to those that
are cascadeless

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Cascading Rollbacks

 Cascading rollback – a single transaction failure


leads to a series of transaction rollbacks. Consider
the following schedule where none of the
transactions has yet committed (so the schedule is
recoverable)

If T10 fails, T11 and T12 must also be rolled back.


Copyright © 2021, ABES Engineering College
 Can lead to the undoing of a significant amount of
h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Recoverability (Cont…)
Timestamp T1 T2 Remarks Before Execution Q=20
1 read(Q); F1 faculty readds Q=20
2 Q=Q+30; F1 faculty added his class count Q=20+30
3 write(Q); Q=50 updated on Stale storage/Disk
4 commit ; Faculty1 committed the Q
5 read(Q); Faculty2 reads committed value of Q using read(Q) as 50 Table 7. 24: Recoverable schedule
6 Q=Q+35; Q is modfied to 75
7 write(Q); Q=75 updated on Stale storage/Disk
8 Fail Due to any reason Faculty1 action's fails. No impact on T2
After Execution Q=75 which is correct and recoverable

T5 T6 T7
Note: Even if a schedule is recoverable, read(A);
to recover correctly from the failure of a read(B);
transaction Ti, we may have to roll back write(A);
several transactions. Such situations read(A);
occur if transactions have read data write(A);
written by Ti, as illustrated in Table 7. 25. read(A);

Table 7.25: Cascading schedule

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Recoverability (Cont…)

 Explanation: Transaction T5 writes a value of A that is read by transaction T6. Transaction T6


writes a value of A that is read by transaction T7. Suppose that, at this point, T5 fails. T5 must be
rolled back. Since T6 is dependent on T5, T6 must be rolled back. Since T7 is dependent on T6,
T7 must be rolled back. This phenomenon, in which a single transaction failure leads to a series
of transaction rollbacks, is called cascading rollback.

 Cascading rollback is undesirable since it leads to the undoing of a significant amount of work. It
is desirable to restrict the schedules to those where cascading rollbacks cannot occur. Such
schedules are called cascadeless schedules. Therefore, we must design the cascadeless
schedule.

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Recoverability (Cont…)
 Strict schedule: If in a schedule, a transaction is neither allowed to read nor write a data item
until the last transaction that has been written it is committed or aborted and then such a schedule
is called a Strict Schedule, an example is shown in Table 7. 26.
 In other words,
 The strict schedule allows only committed read and write operations.
 A strict schedule implements more restrictions than a cascadeless schedule.
T8 T9
write(A);
commit/rollback; Table 7. 26: Strict schedule
read(A)/write(B);

 Note: Strict schedules are stricter than cascadeless schedules. Every strict schedule is a
cascadeless schedule, but vice versa is not true. For easy understanding, looks at Figure 7. 16:

Figure 7. 16: Summary of types of schedules

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Recoverability (Cont…)
 Problem 1: For the given schedule, which schedule is recoverable?
 S1: r1(X), w1(X), r2(X), r1(Y), r2(Y), w2(X), w1(Y), c1, c2;S2: r1(X), r2(X), r1(Z), r3(X), r3(Y),
w1(X),w3(Y), r2(Y), w2(Z), w2(Y), c1, c2, c3;

 Problem 2: Is the given schedule cascadeless or not?


 S1: r1(A),w2(A),r1(B),c1,w3(B), r3(B),w3(A),c3,r2(C),c2;
 S2: r1(A),w2(B),c2,r1(B),w1(B),c1;

Copyright © 2021, ABES Engineering College


h a n g e Pro h a n g e Pro
XC d XC d
F- F-

uc

uc
PD

PD
!

!
W

W
t

t
O

O
N

N
y

y
bu

bu
to

to
ww

ww
om

om
k

k
lic

lic
C

C
.c

.c
w

w
tr re tr re
.

.
ac ac
k e r- s o ft w a k e r- s o ft w a

Thank You

59
Copyright © 2021, ABES Engineering College

You might also like