CH8 Slide
CH8 Slide
CH8 Slide
RECOVERY
AND
QUERY PROCESSING
Learning Objectives
A transaction represents a real‑world event such as the sale
of a product.
A transaction must be a logical unit of work. That is, no
portion of a transaction stands by itself. For example, the
product sale has an effect on inventory and, if it is a credit
sale, it has an effect on customer balances.
A transaction must take a database from one consistent
state to another. Therefore, all parts of a transaction must be
executed or the transaction must be aborted. (A consistent
state of the database is one in which all data integrity
constraints are satisfied.)
Course Contain
Introduction to Transaction Management
ACID Properties
Introduction to Concurrency Control
Reasons of Transaction Failure, System
Recovery and Media Recovery
Introduction to Query Processing
Steps in query Processing
Introduction
A transaction is a logical processing corresponding to a
series of elementary physical operations(reads/writes)
on the DB
Examples:
Transfer of a sum between bank accounts
UPDATE CC UPDATE CC
SET balance=balance-50 SET
balance=balance+50
WHERE account=123 WHERE
account=235
Updating wages of employees in a branch
UPDATE Emp
SET wage=1.1*wage
WHERE branch=‘S01’
Transaction Concept
A transaction is a unit of program execution that accesses
and possibly updates various data items.
A transaction must see a consistent database. During
transaction execution the database may be inconsistent.
When the transaction is committed, the database must be
consistent
Two main issues to deal with:
Failures of various kinds, such as hardware failures and
system crashes
Concurrent execution of multiple transactions
Transactions in DBMS
Transactions are a set of operations used to perform a
logical set of work. A transaction usually means that the
data in the database has changed. One of the major uses
of DBMS is to protect the user’s data from system failures.
It is done by ensuring that all the data is restored to a
consistent state when the computer is restarted after a
crash. The transaction is any one execution of the user
program in a DBMS. Executing the same program multiple
times will generate multiple transactions.
Example –
Transaction to be performed to withdraw cash from an
ATM vestibule.
Set of Operations :
Consider the following example for transaction operations
as follows.
Example -ATM transaction steps.
Transaction Start.
Insert your ATM card.
Select language for your transaction.
Select Savings Account option.
Enter the amount you want to withdraw.
Enter your secret pin.
Wait for some time for processing.
Collect your Cash.
Transaction Completed.
Three operations can be performed in a transaction as follows.
Read/Access data (R).
Write/Change data (W).
Commit.
Example –
Transfer of Rs.500 from Account A to Account B. Initially A= 500,
B= Rs.800. This data is brought to RAM from Hard Disk.
The updated value of Account A = 450 and Account B = 850.
All instructions before commit come under a partially
committed state and are stored in RAM. When the commit is
read the data is fully accepted and is stored in Hard Disk.
If the data is failed anywhere before commit we have to go
back and start from the beginning. We can’t continue from
the same state. This is known as Roll Back.
Transaction failure in between the operations
Suppose T has been executed till Read (Y) and then T’’ starts.
As a result , interleaving of operations takes place due to which
T’’ reads correct value of X but incorrect value of Y and sum
computed by
T’’: (X+Y = 50, 000+500=50, 500)
is thus not consistent with the sum at end of transaction:
T: (X+Y = 50, 000 + 450 = 50, 450).
This results in database inconsistency, due to a loss of 50 units.
Hence, transactions must take place in isolation and changes
should be visible only after they have been made to the main
memory.
Durability
The durability property is used to indicate the performance
of the database's consistent state. It states that the
transaction made the permanent changes.
They cannot be lost by the erroneous operation of a faulty
transaction or by the system failure. When a transaction is
completed, then the database reaches a state known as the
consistent state. That consistent state cannot be lost, even
in the event of a system's failure.
The recovery subsystem of the DBMS has the responsibility
of Durability property.
Transaction States
Transactions can be implemented using SQL queries and Server. In
the below-given diagram, you can see how transaction states
works.
Transaction Support