Adbms Unit 3 Notes
Adbms Unit 3 Notes
Adbms Unit 3 Notes
execution.
computational steps.
transaction.
Once a transaction starts execution, it may terminate in one of the
its execution is stopped, and the already executed actions are undone by
returning the database to the prior state that existed before the start of
Example 7.1
Begin-transaction salary_update begin EXEC SQL UPDATE
EMPLOYEE SET SALARY = SALARY * 1.2 WHERE EMP-ID = “E001”
end
These are
1. Atomicity
2. Consistency
3. Isolation
4. Durability.
Atomicity :
Atomicity refers to the fact that each transaction is a single logical
unit of work in a database environment that may consist of a
number of operations.
Thus, either all operations of a transaction are to be completed
successfully, or none of them are carried out at all.
This property is known as all-or-nothing property of a transaction.
It is the responsibility of the DBMS to maintain atomicity even
when failures occur in the system.
If the execution of a transaction is interrupted by any sort of
failures, the DBMS will determine what actions should be
performed with that transaction to recover from the failed state.
To maintain atomicity during failures, either the system should
complete the remaining operations of the transaction or it should
undo all the operations that have already been executed by the
transaction before the failure.
The execution of a transaction may be interrupted owing to a
variety of reasons such as bad input data, deadlock, system crash,
processor failures, power failure, or media and communication
links failures (in case of distributed system).
The activity of ensuring transaction atomicity in the case of
transaction aborts due to failures caused by bad input data,
deadlock and other factors (except system crash and hardware
failures) is called transaction recovery.
On the other hand, the activity of preserving transaction atomicity
in the case of system crash or hardware failures is called crash
recovery.
Consistency :
Isolation:
Example 7.2.
Assume that there are two concurrent transactions T1 and T2
respectively occurring in a database environment. The
transaction T1 is withdrawing $500 from an account with
balance B, with an initial value of $2,000, while the
transaction T2 is depositing an amount of $600 into the same
account. If these two transactions are executed serially, then
the balance B of the account will be $2,100. Consider that both
the transactions are started nearly at the same time, and both
have read the same value of B, that is, $2,000. Owing to the
concurrent access to the same data item, when the
transaction T1 is decrementing the value of B to $1,500, the
transaction T2 is incrementing the value of B to $2,600. Thus,
update to the data item B made by the transaction T1 will be
overridden by the transaction T2. This is known as lost update
problem.
A set of isolation levels has been defined by ANSI SQL2 [ANSI, 1992]
based on the events dirty read, non-repeatable or fuzzy read and
phantom read, when full isolation is not maintained in a database
environment. These are read uncommitted, read committed,
repeatable read and anomaly serializable. Dirty read refers to
the situation when a transaction reads the dirty data of another
transaction. Fuzzy read or non-repeatable read occurs when one
transaction reads the value of a data item that is modified or deleted
by another transaction. If the first transaction attempts to re-read
the data item, either that data item may not be found or it may read
a different value. Similarly, it is possible that when a transaction is
performing a search operation depending on a selection predicate,
another transaction may be inserting new tuples into the database
satisfying that predicate. This is known as phantom read. The
different isolation levels based on these events are listed below.
Example 7.3.
Example 7.4.
T1: read(X)
T2: write(X)
T2: end transaction
T1: read(X)
Example 7.5.
Durability:
Transaction coordinator:
The transaction coordinator at each site in a distributed
system coordinates the execution of both local and global
transactions initiated at that site.
This component or module is not required in centralized
DBMSs, as there is only one site in a centralized system.
The transaction coordinator at each site performs the
following tasks to coordinate the execution of transactions
initiated at that local site.
It starts the execution of the transactions initiated at that site.
It breaks the transactions into a number of sub-transactions
and distributes these sub-transactions to the appropriate sites
for execution.
It coordinates the termination of the transactions, which may
result in the transactions being committed at all sites or
aborted at all sites.
Classification of Transactions
These classifications have been defined based on various
criteria such as the lifetime of the transaction, organization of
read and write operations within the transaction and the
structure of the transaction.
Depending on their lifetime or duration, transactions can be
classified into two broad categories:
1. Short-duration transactions
2. Long-duration transactions.
A short-duration transaction (also called online
transaction) requires a very short execution/response time
and accesses a relatively small portion of the database.
On the other hand, a long-duration transaction (also called
a batch transaction) requires a longer execution/response
time and generally accesses a larger portion of the database.
Most of the statistical applications – report generation,
complex queries, image processing – are characterized by long-
duration transactions,
whereas most of the current normal database applications
including railway reservation, banking system, project
management require the short-duration category transactions.
Another way to divide transactions into different classes is
based on the organization of the read and the write operations
within the transaction.
In some transactions, read and write operations are organized
in a mixed manner; they do not appear in any specific order.
These are called general transactions.
Some transactions restrict the organization of read and write
operations in such a way that all the read operations within the
transaction are performed before the execution of any write
operation. These transactions are called two-step
transactions.
Similarly, some transactions may restrict that a data item has
to be read before it can be written (updated) within the
transaction operation. These transactions are known
as restricted (or read-before-write) transactions.
If a transaction is characterized by features of both two-step
and restricted transactions, then it is called a restricted two-
step transaction.
Transactions can also be classified into three broad categories
based on the structure of transactions, namely,
1. Flat transactions
2. Nested transactions
3. Workflow models.
A flat transaction has a single start point (begin_transaction)
and a single end point or termination point (end_transaction).
Most of the typical transaction management database
applications are characterized by flat transactions.
Flat transactions are relatively simple and perform well in
short activities, but they are not well-suited for longer
activities.
A nested transaction includes other transactions within its
own start point and end point; thus, several transactions,
called subtransactions, may be nested into one transaction.
o A nested transaction is further classified into two
categories: closed nested transaction and open nested
transaction.
o In a closed nested transaction commit occurs in a
bottom-up fashion, that is, parent transactions are
committed after the commit of sub-transactions or child
transactions that are nested within it, although sub-
transactions are started after the parent transaction.
o On the other hand, open nested transactions provide
flexibility by allowing the commit of the parent
transaction before the commit of sub-transactions.