DBMS Class 12 - Transaction Management - 04.08.2023
DBMS Class 12 - Transaction Management - 04.08.2023
T1 T2
1. read(A)
2. A := A – 50
3. write(A)
read(A), read(B), print(A+B)
4. read(B)
5. B := B + 50
6. write(B
Isolation can be ensured trivially by running transactions serially
That is, one after the other.
However, executing multiple transactions concurrently has significant benefits, as we
will see later.
Transaction State
Active – the initial state; the transaction stays in this state while it is
executing
Partially committed – after the final statement has been executed.
Failed -- after the discovery that normal execution can no longer proceed.
Aborted – after the transaction has been rolled back and the database
restored to its state prior to the start of the transaction. Two options after it
has been aborted:
Restart the transaction
Can be done only if no internal logical error
Kill the transaction
Committed – after successful completion.
Concurrent Executions
Here,
T1 reads the value of X (= 10 say).
T2 reads the value of X (= 10).
T1 updates the value of X (from 10 to 15 say) in the buffer.
T2 again reads the value of X (but = 15).
In this example,
T2 gets to read a different value of X in its second reading.
T2 wonders how the value of X got changed because
according to it, it is running in isolation.
Lost Update Problem-
Here,
T1 reads the value of A (= 10 say).
T1 updates the value to A (= 15 say) in
the buffer.
T2 does blind write A = 25 (write without
read) in the buffer.
T2 commits.
When T1 commits, it writes A = 25 in the
database.
In this example,
T1 writes the over written value of X in
the database.
Thus, update from T1 gets lost.
Phantom Read Problem-
This problem occurs when a transaction reads some variable from the buffer and when
it reads the same variable later, it finds that the variable does not exist.
Here,
T1 reads X.
T2 reads X.
T1 deletes X.
T2 tries reading X but does not find it.
In serial schedules,
All the transactions execute serially one after the other.
When one transaction executes, no other transaction is allowed to execute.
Characteristics-
In non-serial schedules,
Multiple transactions execute concurrently.
Operations of all the transactions are inter leaved or mixed with each
other.
Characteristics-
Serializable Schedules-
No concurrency is allowed.
Concurrency is allowed.
Thus, all the
Thus, multiple transactions can
transactions necessarily execute
execute concurrently.
serially one after the other.
Serial schedules lead to less Serializable schedules improve both
resource utilization and CPU resource utilization and CPU
throughput. throughput.
Serial Schedules are less efficient as Serializable Schedules are always
compared to serializable schedules. better than serial schedules.
(due to above reason) (due to above reason)
Types of Serializability-