Adavanced DBMS Chap 2
Adavanced DBMS Chap 2
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.
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
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
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.
(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.
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
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
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
12/22/2024 Alex. A 30
Lost Update Problem cont....
T2 reads the account A=100
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.
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