DBMS UNIT 3 Transaction
DBMS UNIT 3 Transaction
• Transaction Concept
• Transaction State
• Concurrent Executions
Transaction Concept
• A transaction is a unit of program execution that accesses and
possibly updates various data items.
1. read(A)
2. A := A – 50
3. write(A)
4. read(B)
5. B := B + 50
6. write(B)
Atomicity Requirement
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
Once the user has been notified that the transaction has
completed (i.e., the transfer of the $50 has taken place), the
updates to the database by the transaction must persist even
if there are software or hardware failures.
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.
Transaction State (Cont.)
Concurrent Executions
• Multiple transactions are allowed to run
concurrently in the system.
Advantages are:
– Increased processor and disk utilization, leading to
better transaction throughput
• E.g., one transaction can be using the CPU while another is
reading from or writing to the disk
– Reduced average response time for transactions: short
transactions need not wait behind long ones.
• Concurrency control schemes – mechanisms to
achieve isolation
– That is, to control the interaction among the concurrent
transactions in order to prevent them from destroying
the consistency of the database
Schedules
• Schedule – a sequences of instructions that specify the
chronological order in which instructions of concurrent
transactions are executed
– A schedule for a set of transactions must consist of all
instructions of those transactions
– Must preserve the order in which the instructions appear in
each individual transaction.
• A transaction that successfully completes its execution
will have a commit instructions as the last statement
– By default transaction assumed to execute commit
instruction as its last step
• A transaction that fails to successfully complete its
execution will have an abort instruction as the last
statement
Schedule 1
• Let T1 transfer $50 from A to B, and T2 transfer 10% of the balance
from A to B.
• A serial schedule in which T1 is followed by T2 :
consistent
Inconsistent
Schedule 2
• A serial schedule where T2 is followed by T1
A B A+B Transaction Remark
100 200 300 @start
90 200 290 T2,WRITE A
90 210 300 T2,WRITE B @COMMIT
40 210 250 T1,WRITE A
40 260 300 T1,WRITE B @COMMIT
consistent
Inconsistent
Schedule 3
• Let T1 and T2 be the transactions defined previously. The following schedule is not a
serial schedule, but it is equivalent to Schedule 1
consistent
Inconsistent
Inconsistent @Commit
In Schedules 1, 2 and 3, the sum A + B is preserved.
Schedule 4
• The following concurrent schedule does not
preserve the value of (A + B ).
A B A+B Transaction Remark
100 200 300 @start
90 200 290 T2,WRITE A
90 200 290 T1,WRITE A
90 250 340 T1,WRITE B @COMMIT
90 260 350 T2,WRITE B @COMMIT
consistent
Inconsistent @Transaction
Inconsistent @Commit
Summary
• A task is a database is done as a transaction
that passes through several states.
• Transactions are executed in concurrent
fashion for better throughput.
• Concurrent execution raised Serializability
issues that need to be addressed.
• All schedules may not satisfy ACID properties.
Thanks !
If you have any query please mail me at
[email protected]
Unit III
Schedule 3 Schedule 6
View Serializability
• Let S and S’ be two schedules with the same set of transactions.
S and S’ are view equivalent if the following three conditions are met,
for each data item Q,
1. If in schedule S, transaction Ti reads the initial value of Q, then in
schedule S’ also transaction Ti must read the initial value of Q.
2. If in schedule S transaction Ti executes read(Q), and that value was
produced by transaction Tj (if any), then in schedule S’ also
transaction Ti must read the value of Q that was produced by the
same write(Q) operation of transaction Tj .
3. The transaction (if any) that performs the final write(Q) operation
in schedule S must also perform the final write(Q) operation in
schedule S’.