Professional Documents
Culture Documents
Chapter Two
Chapter Two
5
…cont.
Atomicity
• This means that either the entire transaction
takes place at once or doesn’t happen at all.
• There is no midway i.e. transactions do not
occur partially.
• Each transaction is considered as one unit
and either runs to completion or is not
executed at all.
• It involves the following two operations.
—Abort: If a transaction aborts, changes
made to database are not visible.
—Commit: If a transaction commits,
changes made are visible.
• Atomicity is also known as the ‘All or nothing
rule’.
6
…cont.
• If the transaction fails after completion of T1 but before completion of T2.( say, after write(X)
but before write(Y)), then amount has been deducted from X but not added to Y.
• This results in an inconsistent database state.
• Therefore, the transaction must be executed in entirety in order to ensure correctness of
database state.
7
…cont.
• Consistency
– The integrity constraints must be maintained so that the
database is consistent before and after the transaction.
– It refers to the correctness of a database.
– Referring to the example above, the total amount before and
after the transaction must be maintained.
– Total before T occurs = 500 + 200 = 700.
– Total after T occurs = 400 + 300 = 700
– Therefore, database is consistent.
– Inconsistency occurs in case T1 completes but T2 fails.
– As a result T is incomplete. 8
…cont.
• Isolation
– Transactions occur independently without interference.
– In a database system if more than one transaction are being executed
simultaneously and in parallel,
– the property of isolation states that all the transactions will be carried out and
executed as if it is the only transaction in the system.
– No transaction will affect the existence of any other transaction.
9
…cont.
• 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. 10
…cont.
11
Types of failures and Transaction States
• Failures are classified as transaction, system, and media failures.
• There are several possible reasons for a transaction to fail in the middle of
execution:
– A computer failure (system crash)
• A hardware, software, or network error occurs in the computer system
during transaction execution.
• Hardware crashes are usually media failures—for example, main memory
failure
– A transaction or system error
• integer overflow or division by zero
• because of erroneous parameter values or because of a logical programming error
• the user may interrupt the transaction during its execution.
12
…cont.
– Local errors or exception conditions detected by the
transaction
• Certain conditions may occur that necessitate cancellation of the
transaction
• For example, data for the transaction may not be found
• Insufficient account balance in a banking database, cause a
transaction, such as a fund withdrawal, to be canceled
– Concurrency control enforcement
• It may abort a transaction because it violates serializability
• Or it may abort one or more transactions to resolve a state of deadlock
among several transactions.
13
..cont.
– 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
• The endless list of problems that includes power or air-conditioning
failure, fire, theft, sabotage, overwriting disks or tapes by mistake, and
mounting of a wrong tape by the operator.
14
Transaction States
17
Concurrent Execution of Transactions and its
Advantages
• Concurrency is the ability to allow multiple users to affect
multiple transaction within a database.
• If many transactions try to access the same data, then
inconsistency arises.
• Concurrency control required to maintain
consistency data.
• For example, if we take ATM machines and do not use
concurrency, multiple persons cannot draw money at a
time in different places
18
Concurrent Execution in DBMS
19
…cont.
20
Need for Concurrency Control in DBMS
23
Query Processing in DBMS and Query Optimization
• This section discusses the techniques used internally by a DBMS to
process, optimize, and execute high-level queries.
• Query: A query is a request for information from a database.
• A query expressed in a high-level query language such as SQL must
first be scanned, parsed, and validated.
Steps of query processing
• The scanner identifies the query tokens like SQL keywords, attribute
names, and relation names that appear in the text of the query.
• Parser checks the query syntax to determine whether it is formulated
according to the syntax rules of the query language.
24
…cont.
26
…cont.
27
28