Chapter 3 Transaction Processing Concepts
Chapter 3 Transaction Processing Concepts
• Atomicity.
– Either all operations of the transaction are reflected properly in the
• Consistency.
– Execution of a transaction in isolation (with no other transaction
• Durability
– After a transaction completes successfully, the changes it
has made to the database persist, even if there are
system failures.
Simple Model of a Database
• A database is a collection of data items.
– Because SQL is a powerful and complex language, we
focus on when data are moved from disk to main
memory and main memory to disk.
– write_item(X):
• Writes the value of program variable X into the database
item named X.
Cont’d
• Basic unit of data transfer from the disk to the
named X.
Cont’d
• write_item(X) command includes the following steps:
1. Find the address of the disk block that contains item X.
4. Store the updated block from the buffer back to disk (either
immediately or later).
Cont’d
• The DBMS maintains a number of buffers in the main
execution successfully.
– Such a transaction is aborted.
back.
• We record
modification,
aborting it.
– Aborted, after the transaction has been rolled back and the
database has been restored to its state prior to the start of
the transaction.
– In other words, the processor and disk spend less time idle,
better to let them run concurrently, sharing the CPU cycles and disk
submitted.
Cont’d
followed by T2.
birr, respectively.
Cont’d
Cont’d
• The execution sequences just described are called
schedules.
– They represent the chronological order in which instructions
are executed in the system.
be serial.
– If two transactions are running concurrently,
• the operating system may execute one transaction for a little while, then
perform a context switch, execute the second transaction for some time,
and then switch back to the first transaction for some time, and so on.
the transactions.
Cont’d
• Not all concurrent executions result in a correct state.
the final values of accounts A and B are 950 birr and 2100
birr, respectively.
two transactions.
Cont’d
• It is the job of the database system to ensure that
any schedule that is executed will leave the
database in a consistent state.
• The concurrency-control component of the
database system carries out this task.
Cont’d
• We can ensure consistency of the database under
concurrent execution
– by making sure that any schedule that is executed has
the same effect as a schedule that could have occurred
without any concurrent execution.
exactly
– What operations a transaction performs and
• If I and J refer to the same data item Q, then the order of the two
– If I comes before J, then Ti does not read the value of Q that is written by Tj
in instruction J .
– However, the value obtained by the next read (Q) instruction of S is affected,
since the result of only the latter of the two write instructions is preserved in the
database.
• If there is no other write (Q) instruction after I and J in S, then the order
of I and J directly affects the final value of Q in the database state that
schedule 3.
– The write (A) instruction of T1 conflicts with the read (A)
instruction of T2.
– However, the write (A) instruction of T2 does not conflict with the
schedule S.
order in both schedules except for I and J, whose order does not
matter.
– Since the write (A) instruction of T2 in schedule 3 does not conflict
with the read (B) instruction of T1, we can swap these instructions
– Swap the read (B) instruction of T1 with the read (A) instruction of T2.
– Swap the write (B) instruction of T1 with the write (A) instruction of T2.
• Swap the write (B) instruction of T1 with the read (A) instruction
of T2.
schedule.
Transaction Isolation and Atomicity
• Effect of transaction failures during concurrent
execution.
Cont’d
• If a transaction Ti fails, for whatever reason, we need to
undo the effect of this transaction to ensure the
atomicity property of the transaction.
– In a system that allows concurrent execution, the atomicity
by Ti, the commit operation of Ti appears before the read operation of Tj.
recoverable.
Transaction Isolation Levels
• Serializability is allows programmers to ignore issues
committed.
The isolation levels specified by the SQL
standard are as follows:
• Serializable usually ensures serializable execution.
committed.
Cont’d
• Read uncommitted allows uncommitted data to be
read.
– It is the lowest isolation level allowed by SQL.
committed or aborted.
Locking
• Instead of locking the entire database, a transaction
1. Shared locks are used for data that the transaction reads and
condition.
’Marketing’, 100000);
Cont’d
• The result of our query will be different depending on
query is run.
– In a concurrent execution of these transactions, it is
predicates in queries.
Cont’d
• Let us consider again the query:
– Select ID, name from instructor where salary>
90000;
a predicate.
Cont’d
• In our example query above,
– the predicate is salary > 90000‖, and an update of Wu’s
salary from 90,000 birr to a value greater than 90,000
birr, or an update of Einstein’s salary from a value
greater than 90,000 birr to a value less than or equal to
90,000 birr, would conflict with this predicate.
consistent state.
Cont’d
• Data in volatile storage, such as in RAM, are lost when the computer crashes.
• Data in nonvolatile storage, such as disk, are not lost when the computer
crashes, but may occasionally be lost because of failures such as disk crashes.
• Offline or archival, stable storage may consist of multiple tape copies of data
• It is therefore necessary for the system to control the interaction among the
concurrent transactions.
Cont’d
• Since a transaction is a unit that preserves consistency, a serial
preserved.
transaction.
– We require that any schedule produced by concurrent processing of a set
serializability.
view serializability.
gets aborted.
– Schedules should preferably be Cascadeless, so that the abort of a
committed data.
policies.
Questions