0% found this document useful (0 votes)
3 views

Adavanced DBMS Chap 2

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

Adavanced DBMS Chap 2

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

Collage of health science

department of health informatics


Advanced database management
system

prepared by: Alex. A(MPH)


12/22/2024 Alex. A 1
Chapter 2 Transactions
processing
What is a transaction?
 A Transaction is a mechanism for applying the desired
modifications/operations to a database.
It is evident in real life that the final database instance after a
successful manipulation of the content database is the most up-
to-date copy of the database.
A transaction could be a whole program, part/module of a
program
12/22/2024 or a single command.Alex. A 2
Transaction .....
Changes made in real time to a database are called transactions.
Examples include ATM transactions, credit card approvals, flight
reservations, hotel check-in, phone calls, supermarket canning,
academic registration and billing.
A transaction could be composed of one or more database and non
database operations.
A database transaction is a unit of interaction with database
management system or similar system that is treated in a coherent
and reliable way independent of other transactions.
12/22/2024 Alex. A 3
12/22/2024 Alex. A 4
Distinction between business
transactions and online transactions:
A business transaction is an interaction in the real world, usually
between an enterprise and a person, where something is exchanged.
An online transaction is the execution of a program that performs an
administrative or real-time function, often by accessing shared data
sources, usually on behalf of an online user (although some transactions
are run offline in batch).

12/22/2024 Alex. A 5
Distinction between business transactions
and online transactions cont.....
What we are interested about is the online transaction, which is the
interaction between the users of a database system and the shared data
stored in the database.
This transaction program contains the steps involved in the business
transaction.
Transactions can be started, attempted, then committed or aborted via
data manipulation commands of SQL.
12/22/2024 Alex. A 6
Any transaction can have one of the two
outcomes
Success - transaction commits and database reaches a new consistent
state
Committed transaction cannot be aborted or rolled back.

How do you discard a committed transaction?

Failure - transaction aborts, and database must be restored to consistent


state before it started.
Such a transaction is rolled back or undone.

Aborted transaction that is rolled back can be restarted later.


12/22/2024 Alex. A 7
Any transaction can have one of the two outcomes

In many data manipulation languages, there are keywords used to indicate
different states of a transaction.
The DBMS has no inherent way of knowing the logical grouping of
operations that are supposed to be done together.
Hence, it must provide the users a means to logically group their operations.

Key words such as BEGIN TRANSACTION, COMMIT and ROLLBACK (or their
equivalents) are available in many data manipulation languages to delimit
transactions.
12/22/2024 Alex. A 8
Simple Transaction Model
Simple transaction model is a model of transaction how it must be has active,
partially committed, failed, aborted, and committed states.
Transaction is a several operations that can change the content of the database
which is handled by a single program.
Simple transaction model follows all ACID properties while doing transactions.
Transaction States:
Active
Partially committed
Failed
Aborted
Committed
12/22/2024 Alex. A 9
12/22/2024 Alex. A 10
12/22/2024 Alex. A 11
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.
For 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.
Also, transactions should not interfere with each other.
12/22/2024 Alex. A 12
A transaction is expected to exhibit some basic features or properties
to be considered as a valid transaction. These features are:
A: Atomicity
C: Consistency
I: Isolation
D: Durability

It is referred to as ACID property of a transaction. Without the ACID


property, the integrity of the database cannot be guaranteed.
12/22/2024 Alex. A 13
Atomicity
Is All or None property
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.
No state between Done and Never Started

12/22/2024 Alex. A 14
Consistency
If the transaction code is correct then a transaction, at the end of its
execution, must leave the database consistent.
A transaction should transform a database from one previous consistent
state to another consistent state.
Isolation

A transaction must execute without interference from other concurrent


transactions and its intermediate or partial modifications to data must not
be visible to other transactions.
12/22/2024 Alex. A 15
Durability
The effect of a completed transaction must persist in the database, i.e.,
its updates must be available to other transaction immediately after the
end of its execution, and is should not be affected due to failures after
the completion of the transaction.
In practice, these properties are often relaxed somewhat to provide
better performance.

12/22/2024 Alex. A 16
The transaction sub system of a DBMS
is depicted in the following figure

12/22/2024 Alex. A 17
State of a Transaction
A transaction is an atomic operation from the users’ perspective. But it
has a collection of operations and it can have a number of states during
its execution.
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 COMMIT command.
2. Suicidal Termination: when the transaction detects an error during its
processing and decide to abort itself before the end of the transaction
and perform a ROLL BACK
3. Murderous Termination: When the DBMS or the system force the
execution to abort for any reason. And hence, rolled back.

12/22/2024 Alex. A 18
Ways of Transaction Execution
In a database system many transactions are executed.

Basically there are two ways of executing a set of transactions:

(A) Serially: Serial Execution: In a serial execution transactions are executed strictly
serially.
Thus, Transaction Ti completes and writes its results to the database then only the
next transaction Tj is scheduled for 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.


12/22/2024 Alex. A 19
Ways of Transaction Execution cont.....

12/22/2024 Alex. A 20
Ways of Transaction Execution cont.....

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 to the active.

The worst thing about serial execution is very inefficient resource utilization.
i.e. reduced parallelism.
12/22/2024 Alex. A 21
Ways of Transaction Execution cont.....

12/22/2024 Alex. A 22
Ways of Transaction Execution cont.....

12/22/2024 Alex. A 23
Ways of Transaction Execution
cont....
(B) Concurrently: is the reverse
of serially executable
transactions, in this scheme the
individual operations of
transactions, i.e., reads and
writes are interleaved in some
order.
12/22/2024 Alex. A 24
Ways of Transaction Execution cont...
The correct value of X is 12 but in concurrent execution X =11, which is
incorrect.
The reason for this error is incorrect sharing of X by T1 and T2.

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.

12/22/2024 Alex. A 25
Ways of Transaction Execution cont...
This is the reason the final value of X is one less than what is produced by
serial execution.
But, why concurrent execution? Reasons:  Many systems have an
independent component to handle I/O like l.DMA (Direct Memory Access)
module.
CPU may process other transactions while one is in I/O operation
 Improves resource utilization

 Increases the throughput of the system.


12/22/2024 Alex. A 26
Problems Associated with Concurrent
Transaction Processing
Although two transactions may be correct in themselves, interleaving of
operations may produce an incorrect result which needs control over
access.

Having a concurrent transaction processing, one can enhance the


throughput of the system.

As reading and writing is performed from and on secondary storage, the
system will not be idle during these operations if there is a concurrent
processing.
12/22/2024 Alex. A 27
Problems Associated with Concurrent
Transaction Processing cont...
Every transaction is correct when executed alone, but this would not
guarantee that the interleaving of operations from these transactions will
produce a correct result.
The three potential problems caused by concurrency are:
 Lost Update Problem

 Uncommitted Dependency Problem


 Inconsistent Analysis Problem.
12/22/2024 Alex. A 28
Lost Update Problem
Successfully completed update on a data set by one transaction is
overridden by another transaction/user. E.g. Account with balance A=100.
T1 reads the account A  T1 withdraws 10 from A

T1 makes the update in the Database

T2 reads the account A

T2 adds 100 on A

T2 makes the update in the Database

12/22/2024 Alex. A 29
Lost Update Problem cont....
In the above case, if done one after the other (serially) then we have no
problem.
If the execution is T1 followed by T2 then A=190

If the execution is T2 followed by T1 then A=190

But if they start at the same time in the following sequence:


T1 reads the account A=100

T1 withdraws 10 making the balance A=90

12/22/2024 Alex. A 30
Lost Update Problem cont....
T2 reads the account A=100

T2 adds 100 making A=200

T1 makes the update in the Database A=90

T2 makes the update in the Database A=200

After the successful completion of the operation in this schedule, the


final value of A will be 200 which override the update made by the first
transaction that changed the value from 100 to 90.
12/22/2024 Alex. A 31
Uncommitted Dependency Problem
Occurs when one transaction can see intermediate results of another
transaction before it is committed. E.g.
T2 increases 100 making it 200 but then aborts the transaction before it is
committed.
T1 gets 200, subtracts 10 and make it 190.

But the actual balance should be 90

12/22/2024 Alex. A 32
Inconsistent Analysis Problem
Occurs when transaction reads several values but second transaction
updates some of them during execution and before the completion of the
first. E.g.
T2 would like to add the values of A=10, B=20 and C=30. after the values
are read by T2 and before its completion, T1 updates the value of B to be
50.
At the end of the execution of the two transactions T2 will come up with
the sum of 60 while it should be 90
12/22/2024
since B is updated to 50.
Alex. A 33
Serializability
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.
Schedule: time-ordered sequence of the important actions taken by one
or more transitions.
Schedule represents the order in which instructions are executed in the
system in chronological ordering.

12/22/2024 Alex. A 34
Serializability cont....
The scheduler component of a DBMS must ensure that the individual
steps of different transactions preserve consistency.

A. Serial Schedule: a schedule where the operations of each transaction


are executed consecutively without any interleaved operations from
other transactions.
No guarantee that results of all serial executions of a given set of
transactions will be identical.

12/22/2024 Alex. A 35
Serializability CONT....
B. Non-serial Schedule: Schedule where operations from a set of concurrent
transactions are interleaved.
The objective of serializability is to find non-serial schedules that allow
transactions to execute concurrently without interfering with one another.
In other words, want to find non-serial schedules that are equivalent to some
serial schedule. Such a schedule is called serializable.

12/22/2024 Alex. A 36
Serializability cont....
If a non serial schedule can come up with a result equivalent to some
serial schedule, we call the schedule Serializable. To mean that the
sequence of the execution of the operations will result in a value identical
with serially executed transaction, which always is correct.
Thus Serializability identifies those concurrent executions of transactions
guaranteed to ensure consistency.

12/22/2024 Alex. A 37
Serialization
Objective of serialization is to find schedules that allow transactions to
execute concurrently without interfering with one another.
If two transactions only read data, order is not important.
If two transactions either read or write completely separate data items, they
do not conflict and order is not important.
If one transaction writes a data item and another reads or writes the same
data item, order of execution is important
Possible solution: Run all transactions serially.
This is often too restrictive as it limits degree of concurrency or parallelism
in system.

12/22/2024 Alex. A 38
Test for Serializability
Constrained write rule: transaction updates data item based on its old value,
which is first read by the transaction. 
 Under the constrained write rule we can use precedence graph to test for
serializability.
A non serial schedule can be tasted for serializability by using a method called
precedence graph.
A precedence graph is composed of: Nodes to represent the transactions, and
Arc(directed edge) to connect nodes indicating the order of execution for the
transactions
12/22/2024 Alex. A 39
12/22/2024 Alex. A 40

You might also like