DBMS CH-3
DBMS CH-3
CHAPTER THREE
02/24/2023
1
Transaction
A transaction is typically implemented by a computer program, which
includes database commands such as retrievals, insertions, deletions, and
updates.
Transaction is a mechanism for applying the desired modifications /
operations to a database
Any changes made in real time to a database are called transactions.
In database field, a transaction is a group of logical operations that must
all succeed or fail as a group.
02/24/2023 2
Systems dedicated for supporting transaction such operations are
known a transaction processing systems(TPS).
02/24/2023 3
Transaction processing systems are systems with large databases
and hundreds of concurrent users executing database transactions.
Examples of such systems include airline reservations, banking
system, credit card processing, stock markets, supermarket checkouts,
and many other applications.
These systems require high availability and fast response time for
hundreds of concurrent users.
02/24/2023 4
Transaction: Logical unit of database processing that includes one or more
access operations (read -retrieval, write - insert or update-delete)
02/24/2023 5
We can have one of the following two outcomes for any transaction:
02/24/2023 6
States of Transactions
1. Active state
3. Failed state
4. Aborted state:
5. Committed state
02/24/2023 7
1. Active state: In this state, the transaction is being executed. This is the initial
state of every database transaction.
02/24/2023 8
4. Aborted state: If any of the checks fails and the transaction has
reached a failed state, then the recovery manager rolls back all its write
operations on the database to bring the database back to its original
state where it was prior to the execution of the transaction.
Transactions in this state are called aborted.
The database recovery module can select one of the two operations
after a transaction aborts:
A. Re-start the transaction
B. Kill the transaction
02/24/2023 9
5. Committed state: If a transaction executes all its operations
02/24/2023 10
The following diagram representing different states in database transaction:
02/24/2023 11
A transaction can end in three possible ways
1. Successful Termination: when a transaction completes the execution of all
operations in it and reaches the COMMITED state.
DBMS Classifies system in to two based on number of users who are accessing the system concurrently
1. Single user system :- if at most one user using the system at a time.
2. Multi-user system: - if many users can use the system—and hence access the database concurrently.
Most of today’s DBMSs are multiuser. For example, an airline reservations system I used by hundreds
02/24/2023 13
Single-User vs. Multiuser Systems
In a multiuser DBMS, the stored data items are the primary
resources that may be accessed concurrently by interactive users or
application programs, which are constantly retrieving information
from and modifying the database.
02/24/2023 15
• As illustrated in Figure below, which shows two processes, A and B,
executing concurrently in an interleaved fashion. Interleaving keeps
the CPU busy when a process requires an input or output (I/O)
operation, such as reading block from disk. The CPU is switched to
execute another process rather than remaining idle during I/O time.
Interleaving also prevents a long process from delaying other
processes.
If the computer system has multiple hardware processors (CPUs), parallel
processing
02/24/2023
of multiple processes is possible, as illustrated by processes C16and D
Interleaved processing versus parallel processing of concurrent transactions
02/24/2023 17
A single transaction might require several queries, each reading and/or
writing information in the database. When this happens it is usually
important to be sure that the database is not left with only some of the
queries carried out
example, when doing a money transfer, if the money was debited from
one account, it is important that it also be credited to the depositing
account Transactions should not interfere with each other which leads to
inconsistent results.
02/24/2023 18
Transactions, Database Items, Read and Write Operations
A transaction includes one or more database access operations—these
include insertion, deletion, modification, or retrieval operations. The
database operations that form a transaction can either be embedded
within an application program or they can be specified interactively
via a high-level query language such as SQL
02/24/2023 19
If the database operations in a transaction do not update the database but only
Basic operations done on the database during transactions are read and write
02/24/2023 20
read_item(X): Reads a database item named X into a program variable. To
simplify our notation, we assume that the program variable is also named X.
Read and Write Operations: Basic unit of data transfer from the disk to the
computer main memory is one block. In general, a data item (what is read or
written) will be the field of some record in the database
02/24/2023 21
Executing a read_item(X) command includes the following steps:
1. Find the address of the disk block that contains item X.
2. Copy that disk block into a buffer in main memory (if that disk block
is not already in some main memory buffer).
02/24/2023 22
Executing a write_item(X) command includes the following steps:
1. Find the address of the disk block that contains item X.
2. Copy that disk block into a buffer in main memory (if that disk block is
not already in some main memory buffer).
3. Copy item X from the program variable named X into its correct location
in the buffer.
4. Store the updated block from the buffer back to disk (either immediately
or at some later point in time).
02/24/2023 23
Ways of Executing Transaction
In a database system many transactions are executed. Basically there are two
ways of executing a set of transactions:
1. Serial Execution
2. Concurrent execution
02/24/2023 24
Serial Execution……
This means at one time there is only one transaction is being executed in
the system. The data is not shared between transactions at one specific time
In Serial transaction execution, one transaction being executed does not
interfere the execution of any other transaction.
Good things about serial execution
Correct execution, i.e., if the input is correct then output will be correct.
Fast execution, since all the resources are available for the active transaction.
02/24/2023 25
02/24/2023 26
02/24/2023 27
2. Concurrent execution
02/24/2023 28
02/24/2023 29
Concurrent execution………
Final values at the end of T1 and T2: X = 11, and Y = 7
In serial execution T2 read the value of X written by T1 (i.e., 11) but in
concurrent execution T2 read the same value of X (i.e., 10) as T1 did and the
update made by T1 was overwritten by T2’s update.
02/24/2023 30
Problem associated with concurrent transaction
This occurs when two transactions that access the same database items have their
operations interleaved in a way that makes the value of some database item incorrect
fails for some reason The updated item is accessed by another transaction before
it is changed back to its original value.
02/24/2023 31
Problem associated with concurrent transaction……
02/24/2023 32
Desirable Properties of Transactions
1. Atomicity.
3. Isolation
4. Durability / permanency
02/24/2023 33
1. Atomicity.
A transaction is an atomic unit of processing; it should either be performed in its entirety or not
performed at all.
Every transaction should be considered as an atomic process which can not be sub divided into
small tasks. Due to this property, just like an atom which exists or does not exist, a transaction
has only two states. Done or Never Started
Done - a transaction must complete successfully and its effect should be
visible in the database
Never Started - If a transaction fails during execution then all its modifications must be undone
to bring back the database to the last consistent state, i.e., remove the effect of failed transaction.
02/24/2023 34
2. Consistency/ behaving similarly:
02/24/2023 37
What causes a Transaction to fail?
A computer failure (system crash): A hardware or software error occurs in the
computer system during transaction execution. If the hardware crashes, the contents of
the computer’s internal memory may be lost.
A transaction or system error: Some operation in the transaction may cause it to fail,
such as integer overflow or division by zero. Transaction failure may also occur because
of erroneous parameter values or because of a logical programming error. In addition,
the user may interrupt the transaction during its execution.
Local errors or exception conditions detected by the transaction: Certain conditions
necessitate cancellation of the transaction. For example, data for the transaction may not
be found. A condition, such as insufficient account balance in a banking database, may
cause a transaction, such as a fund withdrawal from that account, to be canceled
02/24/2023 38
What causes a Transaction to fail?
Concurrency control enforcement: The concurrency control
method may decide to abort the transaction, to be restarted later,
because it violates serializability or because several transactions are
in a state of deadlock.
Disk failure: Some disk blocks may lose their data because of a read
or write malfunction or because of a disk read/write head crash. This
may happen during a read or a write operation of the transaction.
Physical problems and catastrophes: This refers to an endless list
of problems that includes power or air-conditioning failure, fire, theft
and etc.
02/24/2023 39
Schedules based on recoverability
In any transaction processing system, if concurrent processing is implemented, there
will be concept called schedule having or determining the execution sequence of
operations in different transactions.
The scheduler component of a DBMS must ensure that the individual steps
of different transactions preserve consistency.
02/24/2023 40
Schedules classified on the base recoverability as follows
1. Recoverable schedule:
2. Cascadeless schedule:
One where every transaction reads only the items that are written by committed
transactions.
3. Strict Schedules:
A schedule in which a transaction can neither read nor write an item X until the last
transaction
02/24/2023 that wrote X has committed. 41
The schedules based on serializability can be of two types:-
1. Serial Schedule
2. Non serial schedules
Serial Schedule: a schedule where the operations of each transaction
are executed consecutively without any interleaved operations from
other transactions
Non-serial Schedule: Schedule where operations from a set of
concurrent transactions are interleaved.
02/24/2023 42
The objective of serializability is to find non-serial schedules that
allow to execute transactions concurrently without interfering with
one another.
02/24/2023 43
02/24/2023 44
THE END OF CHAPTER THREE
02/24/2023 45