DBMS Notes
DBMS Notes
Transaction:- A transaction is logical unit of database processing that include one or more
database access operations these can include insertion, deletion, modification or retrieval
operation. But we are inserted only read and write.
3.Copy item x from the program variable name x into the correct location in the butter.
4.Store the update block from the butter back to the disk .
Ex- of transaction:-
T1 T2
X: X-N X: X+M
Read_ item(y)
Y: Y+N
Now we discuss the types of problem. We encounter with these two transactions if they run
concurrently.
A: A-100 A: A-100
Commit T2
A=500 A=500
A=400 A=400
W: (400) W: (400)
T1 T2
A: A-100 A=400
A: A+10% of A A=440
B: = B +10% of B B=770
Commit T2
B: =B +100 B =870
Commit T1
The database is not consistent after adding 10% interest to all account the total amount should be
R.s 1320 . Where as after the completion of transaction in the above inter leave manner total
amount is R.s 1210.
500+50=550
A=700 700*10/100=70
700+70=770
Total=1320
The problem read occurs when transaction updates a database item and then the
transaction tails for some reason . The update item is access by another transaction before it is
change to back its original value.
T1 T2
X: = X- N;
Write_ item(X)
X: X +M
Write _ item(X)
Must change the value of X back to its old value : meanwhile T2 has read the temporary
incorrect value of X.
Let us assume that transaction T1 reads the database object A. While the transaction T1 is
still in progress, transaction T2 updates the data item A and commits it. Meanwhile T1 again
reads A to find that it has a different value even through it has not modified it .
T1 T2
X =X+2
At this point it may be necessary to check whether the changes introduced by the transaction can
be permanently applied to the database or transaction tailed.
Isolation = Execution of a transaction should not be interfered with by any other transaction
executing concurrently.
SYSTEM LOG
1. [start _ transaction, T]
2. [Write _ item, T, X. old _ value, new _ value]
3. [read _ item, T, X]
4. [committed, T]
5. [abort, T]
Schedule:-
A schedule S of N transactions T1,T2…… Tn is an ordering of operations of the
transactions subject to the constraint that for each transaction that participates in S , the operation
of T1 in S must appear in the same order in which they occur in T1.
Ex. Of Schedules
S1: RT1(X) RT1(Y) WT1(X) WT1(Y) RT2(X) RT2(Y) WT2(X) WT2(Y) RT3(X) RT3(Z) WT3(X)
WT3(Z) RT3(X) WT3(Y)
S2: RT1(X) RT2(X) RT3(X) RT1(Y) RT2(Y) RT3(Z) WT1(X) WT2(X) WT3(X) WT1(Y) WT2(Y) WT3(Z)
RT3(X) WT3(Y)
Conflict Operation:-
Ex:-
RT1(X), WT2(X)
Recoverability of Schedules:-
A schedule S is said to be recoverable it no transaction T in S commits until all
transactions T that have written an item that T reads have committed.
S2:- RT1(x) RT1(y), WT1(x) WT1(y) RT2(x) RT2(y) WT2(x) WT2(y) RT3(x) RT3(z) WT3(x) WT3(z) RT3(y)
WT3(y) commit T1 commit T2 commit T3
Serial Schedule:-
A schedule S is a serial if for every transaction T participating in the schedule all the
operations of T are executed consecutively in the schedule otherwise the schedule is called non-
serial.
T1 T2 T1 T2
500 write_item(x)
Result Equivalent
Serializability :- Determine which of the non-serial schedules always give a correct result &
which may give erroneous results . The concept used to characterized schedules in this manner is
that of serialzability of a schedule.
Equivalent:-
1) Result Equivalent:- Two schedules are result equivalent if they produce the same final
state of the database.
A schedule S of N transaction is result serializable if it is result equivalent to
some serial schedule.
S1 S2 X=100
1. Conflict Equivalent – Two schedules are said to conflict equivalent if the order of any two
conflicting operations is the same in both schedules.
A schedule is S to be conflict serializable if it is conflict equivalent to some serial
schedules S’
T1 T2
read_item (X)
X := X-N
Write_item (X)
read_item (X)
X := X+N
write_item (X)
read_item (Y)
Y := Y+N
write_item (Y)
Conflict Equivalent
T1 T2 T3
read_item (Z)
read_item (Y)
write_item (Y)
read_item (Y)
read_item (Z)
read_item (X)
write_item (Z)
read_item (X)
read_item (Y)
read_item(Y)
write_item (X)
T1 X,Y T2
T1 T2 T3
read_item (Y)
read_item (Z)
read_item (X)
write_item (Z)
read_item (Z)
read_item (Y)
read_item(Y)
write_item (Y)
write_item (Y)
read_item (X)
write_item (X)
T1 X,Y T2
Y Y,Z
T3
View Serialzability – The schedules S & S1 are said to be view equivalent if the following three
conditions are met:
1. For each data item Q if transaction T i reads the initial value of Q in schedule S, then
transaction Ti must be in schedule S1 also read the initial value of Q.
2. For each data item Q if transaction Ti executes read (Q) in schedule S1 and that value was
produced by transaction Tj (if any), then transaction Ti must in schedule S1, also read the
value of Q that was produced by transaction Tj.
3. For each data item Q, the transaction (if any) that performs the final write (Q) operation
in schedule S must perform the final write (Q) operation in S1.
T1 T2 T1 T2 T1 T2
read (A) read(A) read (A)
A := A-50 temp := A*0.1 A := A-50
write (A) A := A – temp write(A)
read (B) write (A) read(A)
B := B+50 read(B) temp := A*0.1
write (B) B := B+ temp
read (A) write (B)
temp := A*0.1 read (A)
A := A – temp A := A + 50
write (A) write(A)
read (B) read(B)
B := B + temp B := B+50
write (B) write (B)
Wait Die:
If TS(Ti) < (Tj) then allow Ti to wait for Tj to release its lock otherwise abort and restart
Ti with the same timestamp.
Wound – Wait:
If TS(Ti) < (Tj) then abort Tj and restart Tj with the same timestamp. Otherwise
let Ti wait for Tj to release its lock.
T1: R1(A) W1(A) R1(B) W1(B) R1(C) W1(C) R1(D) W1(D) R1(E) W1(E)
T2: R2(E) W2(E) R2(A) W2(A) R2(B) W2(B) R2(H) W2(H)
T3: R3(F) W3(F) R3(B) W3(B)
T1 E T2
T3
Logging with Differed Updates: This approach is concerned with following updates:
begin T
A := A – 100 01 begin T
B := B+100 04 commit T
WT(B) 05 end T
Commit T
end T
Logging with Immediate Updates: In this approach all the updates of a transaction are posted
to a database immediately and a record is kept in log. In such situations every update type of
record in log must keep track of old value as well as new value.
Lock: A lock is a variable associated with a data item and describes the states of the item with
respect to applicability of reads, writes of a schedule. There is one lock for each data item.
Binary Lock: Having just two possible states namely lock and unlock.
Two Phase Lock Protocol (2PL): A transaction obeys two phase locking mechanism if in one
phase it locks all the required items and in the second phase it unlocks these items. These two
phases are called growing and shrinking phases. There are 2 types of 2PL:
1. Strict 2PL: In this scheme two phases obey the following:
2. Conservative 2PL:
a. In this scheme the transaction pre declares which items it will work with and it
acquires all locks before any work is done.
b. Lock is released when transaction finishes its activities on the item.
3. Rigrous 2PL:
a. In this variation a transaction T does not release any of its lock (exclusive or
shared) until after it commits or aborts.
Strict:
X(A) R(A) W(A) X(B) R(B) W(B) XR(C) U(C) X(D) R(D) W(D) U(A) U(B) U(D)
Rigrous:
X(A) R(A) W(A) X(B) R(B) W(B) X(C) R(C) W(C) X(D) R(D) W(D) U(A) U(B) U(C) U(D)
Distributed Database:
Characteristics:
Location Transparency
Replication
Formulation
Advantages:
Local Control of Data
Increasing Database Capacity
System Availability
Added Efficiency
Disadvantages:
Update of replicated data
More complex query processing
Complex Shared data management.
Complex Recovery
Difficult Management of Data Dictionary
Complex Database Design