Advanced Database Chapter 3
Advanced Database Chapter 3
B B B
CPU2
A A
CPU1 A
CPU1
time
t1 t2 t1 t2
Interleaved processing Parallel processing
(Single processor) (Two or more processors)
Introduction(cont..)
Why concurrency control(during multiple transaction
Execution) is needed?
Three problems are
1. The lost update problem
2. The temporary update (dirty read) problem
3. Incorrect summary problem
A Transaction: A Formal Example
T1
t0
read_item(X);
read_item(Y);
X:=X - 400000;
Y:=Y + 400000;
write _item(X);
tk
write_item(Y);
Problems in concurrent execution of
Transaction(Lost Update)
ACID properties
Atomicity
Consistency
Isolation
Durability
Atomicity and Consistency
Atomicity Consistency
Transactions are atomic – Transactions take the
they don’t have parts database from one
(conceptually) consistent state into
can’t be executed another
partially; it should not be In the middle of a
detectable that they transaction the database
interleave with another might not be consistent
transaction
Isolation and Durability
Isolation Durability
The effects of a transaction Once a transaction has
are not visible to other completed, its changes are
transactions until it has made permanent
completed Even if the system crashes,
the effects of a transaction
must remain in place
Properties of Transaction(cont..)
S1 S2
read_item(X); read_item(X);
X:=X+10; X:=X*1.1;
write_item(X); write_item(X);
Schedules S1 and S2 are result equivalent for X=100 but not in general
Conflict Equivalent schedule(example)
Schedule S1
T1 T2
read_item(A);
write_item(A);
order doesn’t matter
order matters
read_item(B);
write_item(B);
read_item(A):
write_item(A);
read_item(B);
order matters order
write_item(B);
doesn’t matter
Conflict Equivalence(Example)
Schedule S1’
T1 T2
read_item(A);
read_item(B);
write_item(A); same order as in S1
read_item(A):
write_item(B); same order as in S1 write_item(A);
Two schedules are conflict equivalent, if the order of any two conflicting operations is the same in
both schedules
Transaction Support in SQL
A single SQL statement is always considered to be atomic.
There is no explicit Begin_Transaction statement.
SET TRANSACTION statement in SQL2 sets the characteristics of a
transaction.
Access mode
READ only or READ-WRITE
Diagnostic area size
Indicates the number of conditions that can be held simultaneously in the
diagnostic area.
Isolation level
READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ,
SERIALIZABLE