C. K. Pithawalla College of
Engineering & Technology
Enrollment No Name
160090107017 Yogita Jain Prof. Chetan k. Solanki
160090107021 Jinal Kharose Prof. Saurabh S. Tandel
160090107031 Dhruvi Patel
160090107036 Namrata Patel
160090107045 Saloni Agrawal
Branch:-Computer 2st Year (Div D)
ALA Subject:- Database Management System
ALA Topic Name:- Transactions
Group No:-B-08
Submitted To
Index
• Transaction
• ACID Properties
• Example of Transfer
• Serializablity
• Conflict Serializablity
• View Serializablity
• Testing for Serializablity
• Testing for Conflict Serializablity
• Testing for View Serializablity
 Collection of operations that form a single logical unit of
work are called Transaction.
 A transaction is a unit of program execution that accesses
and possibly updates various data items.
 A transaction must see a consistent database. During
transaction execution the database may be inconsistent.
 When the transaction is committed, the database must be
consistent.
Two main issues to deal with: Failures of various kinds,
such as hardware failures and system crashes Concurrent
execution of multiple transactions
• A program contains statements of the form begin
and end transaction.
The transaction consists of all operations executed between the begin
transaction and end transaction.
Thus a transaction is the DBMS’s abstract view of a user program: a
series of reads/writes of database objects.
Simple example of transaction
Suppose we are working on a system for a bank. A
customer goes to the ATM and instructs it to
transfer Rs. 1000 from savings to a checking
account. This simple transaction requires two
steps:-
1. Subtracting the money from the savings account
balance.
2. Adding the money to the checking account
balance.
ACID Properties
To ensure integrity of data, the database system must maintain:
• Atomicity. Either all operations of the transaction are properly
reflected in the database or none are.
• Consistency. Execution of a transaction in isolation preserves
the consistency of the database.
• Isolation. Although multiple transactions may execute
concurrently, each transaction must be unaware of other
concurrently executing transactions.
– That is, for every pair of transactions Ti and Tj, it appears to Ti
that either Tj, finished execution before Ti started, or Tj started
execution after Ti finished.
• Durability. After a transaction completes successfully, the
changes it has made to the database persist, even if there are
system failures.
Process of Transaction
The transaction is executed as a series of reads and writes of database
objects, which are explained below:
 Read Operation
• To read a database object, it is first brought into main memory from
disk, and then its value is copied into a program variable as shown in
figure.
• Write Operation
To write a database object, an in-memory copy of the object is first
modified and then written to disk.
Example Of Transfer
• Transaction to transfer $100 from Checking account A to Saving account B:
1. read(A)
2. A := A – 100
3. write(A)
4. read(B)
5. B := B + 100
6. write(B)
Consistency requirement – the sum of A and B is unchanged by the execution
of the transaction.
Atomicity requirement — if the transaction fails after step 3 and before step 6,
the system should ensure that its updates are not reflected in the database,
else an inconsistency will result.
Durability requirement — once the user has been notified that the transaction
has completed (i.e., the transfer of the $100 has taken place), the updates
to the database by the transaction must persist despite failures.
Isolation requirement — if between steps 3 and 6, another transaction is
allowed to access the partially updated database, it will see an inconsistent
database.
Serializability
The database system must control concurrent execution of
transaction , to ensure that the database state remains
consistent.
• Serializability:-It is the process of finding concurrent
schedule equivalent to serial schedule
• Thus serial execution of a set of transactions preserves
database consistency.
• A (possibly concurrent) schedule is serializable if it is
equivalent to a serial schedule.
• Different forms of schedule equivalence give rise to the
notions of:
1. conflict serializability
2. view serializability
• Transactions are programs.
• Here we consider only two operations READ and WRITE
Conflict Serializability
• Instructions Ii and Ij of transactions Ti and Tj respectively, conflict if and only
if there exists some item Q accessed by both Ii and Ij , and at least one of
these instructions wrote Q.
1. Ii = read ( Q), Ij = read ( Q ). Ii and Ij don’t conflict.
2. Ii = read ( Q), Ij = write ( Q ). They conflict.
3. Ii = write ( Q), Ij = read ( Q ). They conflict
4. Ii = write ( Q), Ij = write ( Q ). They conflict
• Intuitively, a conflict between Ii and Ij forces a (logical) temporal order
between them. If Ii and Ij are consecutive in a schedule and they do not
conflict, their results would remain the same even if they had been
interchanged in the schedule.
• If a schedule S can be transformed into a schedule S´ by a series of swaps of
non-conflicting instructions, we say that S and S´ are conflict equivalent .
• We say that a schedule S is conflict serializable if it is conflict equivalent to
a serial schedule.
• It is possible to have two schedules that produce the same outcome ,but
that are not conflict equivalent.
Not conflict equivalent
Conflict Equivalent
Conflict Serializable
• Schedule 3 below can be transformed into Schedule 1, a
serial schedule where T2 follows T1 , by series of swaps of
non-conflicting instructions. Therefore Schedule 3 is
conflict serializable.
View Serializability
• Another schedule equivalence is purely based on read and write
operations.
• 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:
1. For each data item Q, if transaction Ti reads the initial value of Q in
schedule S, then transaction Ti must, in schedule S´ , also read the
initial value of Q.
2. For each data item Q if transaction Ti executes read ( Q) in schedule S
, and that value was produced by transaction Tj (if any), then
transaction Ti must in schedule S´ 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 schedule S´ .
• A schedule S is view serializable it is view equivalent to a serial
schedule.
• Every conflict serializable schedule is also view serializable.
• A schedule which is view-serializable but not conflict serializable.
• Every view serializable schedule that is not conflict serializable has
blind writes.
Not View Equivalent
View Equivalent
Testing for Serializability
Consider some schedule of a set of transactions T1 T2, ..., Tn
• Precedence graph — a direct graph where the vertices are the
transactions (names).
• We draw an arc from Ti to Tj if the two transaction conflict, and Ti
accessed the data item on which the conflict arose earlier.
• We may label the arc by the item that was accessed.
Example Schedule
(Schedule A)
Precedence Graph
(Schedule A)
Test for Conflict Serializability
• A schedule is conflict serializable if and only if its
precedence graph is acyclic.
• Cycle-detection algorithms exist which take order n 2 time,
where n is the number of vertices in the graph. (Better
algorithms take order n + e where e is the number of
edges.)
• If precedence graph is acyclic, the serializability order can
be obtained by a topological sorting of the graph. This is a
linear order consistent with the partial order of the graph.
For example, a serializability order for Schedule A would be
T5 → T4 → T3 → T2 → T1
Test for View Serializability
• The precedence graph test for conflict serializability
must be modified to apply to a test for view
serializability.
• The problem of checking if a schedule is view
serializable falls in the class of NP -complete
problems. Thus existence of an efficient algorithm is
unlikely. However practical algorithms that just
check some sufficient conditions for view
serializability can still be used.
Transaction and serializability

Transaction and serializability

  • 1.
    C. K. PithawallaCollege of Engineering & Technology Enrollment No Name 160090107017 Yogita Jain Prof. Chetan k. Solanki 160090107021 Jinal Kharose Prof. Saurabh S. Tandel 160090107031 Dhruvi Patel 160090107036 Namrata Patel 160090107045 Saloni Agrawal Branch:-Computer 2st Year (Div D) ALA Subject:- Database Management System ALA Topic Name:- Transactions Group No:-B-08 Submitted To
  • 2.
    Index • Transaction • ACIDProperties • Example of Transfer • Serializablity • Conflict Serializablity • View Serializablity • Testing for Serializablity • Testing for Conflict Serializablity • Testing for View Serializablity
  • 3.
     Collection ofoperations that form a single logical unit of work are called Transaction.  A transaction is a unit of program execution that accesses and possibly updates various data items.  A transaction must see a consistent database. During transaction execution the database may be inconsistent.  When the transaction is committed, the database must be consistent. Two main issues to deal with: Failures of various kinds, such as hardware failures and system crashes Concurrent execution of multiple transactions
  • 4.
    • A programcontains statements of the form begin and end transaction. The transaction consists of all operations executed between the begin transaction and end transaction. Thus a transaction is the DBMS’s abstract view of a user program: a series of reads/writes of database objects.
  • 5.
    Simple example oftransaction Suppose we are working on a system for a bank. A customer goes to the ATM and instructs it to transfer Rs. 1000 from savings to a checking account. This simple transaction requires two steps:- 1. Subtracting the money from the savings account balance. 2. Adding the money to the checking account balance.
  • 6.
  • 7.
    To ensure integrityof data, the database system must maintain: • Atomicity. Either all operations of the transaction are properly reflected in the database or none are. • Consistency. Execution of a transaction in isolation preserves the consistency of the database. • Isolation. Although multiple transactions may execute concurrently, each transaction must be unaware of other concurrently executing transactions. – That is, for every pair of transactions Ti and Tj, it appears to Ti that either Tj, finished execution before Ti started, or Tj started execution after Ti finished. • Durability. After a transaction completes successfully, the changes it has made to the database persist, even if there are system failures.
  • 8.
    Process of Transaction Thetransaction is executed as a series of reads and writes of database objects, which are explained below:  Read Operation • To read a database object, it is first brought into main memory from disk, and then its value is copied into a program variable as shown in figure.
  • 9.
    • Write Operation Towrite a database object, an in-memory copy of the object is first modified and then written to disk.
  • 10.
    Example Of Transfer •Transaction to transfer $100 from Checking account A to Saving account B: 1. read(A) 2. A := A – 100 3. write(A) 4. read(B) 5. B := B + 100 6. write(B) Consistency requirement – the sum of A and B is unchanged by the execution of the transaction. Atomicity requirement — if the transaction fails after step 3 and before step 6, the system should ensure that its updates are not reflected in the database, else an inconsistency will result. Durability requirement — once the user has been notified that the transaction has completed (i.e., the transfer of the $100 has taken place), the updates to the database by the transaction must persist despite failures. Isolation requirement — if between steps 3 and 6, another transaction is allowed to access the partially updated database, it will see an inconsistent database.
  • 11.
    Serializability The database systemmust control concurrent execution of transaction , to ensure that the database state remains consistent. • Serializability:-It is the process of finding concurrent schedule equivalent to serial schedule • Thus serial execution of a set of transactions preserves database consistency. • A (possibly concurrent) schedule is serializable if it is equivalent to a serial schedule. • Different forms of schedule equivalence give rise to the notions of: 1. conflict serializability 2. view serializability
  • 12.
    • Transactions areprograms. • Here we consider only two operations READ and WRITE
  • 13.
    Conflict Serializability • InstructionsIi and Ij of transactions Ti and Tj respectively, conflict if and only if there exists some item Q accessed by both Ii and Ij , and at least one of these instructions wrote Q. 1. Ii = read ( Q), Ij = read ( Q ). Ii and Ij don’t conflict. 2. Ii = read ( Q), Ij = write ( Q ). They conflict. 3. Ii = write ( Q), Ij = read ( Q ). They conflict 4. Ii = write ( Q), Ij = write ( Q ). They conflict • Intuitively, a conflict between Ii and Ij forces a (logical) temporal order between them. If Ii and Ij are consecutive in a schedule and they do not conflict, their results would remain the same even if they had been interchanged in the schedule. • If a schedule S can be transformed into a schedule S´ by a series of swaps of non-conflicting instructions, we say that S and S´ are conflict equivalent . • We say that a schedule S is conflict serializable if it is conflict equivalent to a serial schedule. • It is possible to have two schedules that produce the same outcome ,but that are not conflict equivalent.
  • 14.
  • 15.
  • 16.
  • 17.
    • Schedule 3below can be transformed into Schedule 1, a serial schedule where T2 follows T1 , by series of swaps of non-conflicting instructions. Therefore Schedule 3 is conflict serializable.
  • 18.
    View Serializability • Anotherschedule equivalence is purely based on read and write operations. • 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: 1. For each data item Q, if transaction Ti reads the initial value of Q in schedule S, then transaction Ti must, in schedule S´ , also read the initial value of Q. 2. For each data item Q if transaction Ti executes read ( Q) in schedule S , and that value was produced by transaction Tj (if any), then transaction Ti must in schedule S´ 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 schedule S´ .
  • 19.
    • A scheduleS is view serializable it is view equivalent to a serial schedule. • Every conflict serializable schedule is also view serializable. • A schedule which is view-serializable but not conflict serializable. • Every view serializable schedule that is not conflict serializable has blind writes.
  • 20.
  • 21.
  • 22.
    Testing for Serializability Considersome schedule of a set of transactions T1 T2, ..., Tn • Precedence graph — a direct graph where the vertices are the transactions (names). • We draw an arc from Ti to Tj if the two transaction conflict, and Ti accessed the data item on which the conflict arose earlier. • We may label the arc by the item that was accessed.
  • 23.
  • 24.
    Test for ConflictSerializability • A schedule is conflict serializable if and only if its precedence graph is acyclic. • Cycle-detection algorithms exist which take order n 2 time, where n is the number of vertices in the graph. (Better algorithms take order n + e where e is the number of edges.) • If precedence graph is acyclic, the serializability order can be obtained by a topological sorting of the graph. This is a linear order consistent with the partial order of the graph. For example, a serializability order for Schedule A would be T5 → T4 → T3 → T2 → T1
  • 25.
    Test for ViewSerializability • The precedence graph test for conflict serializability must be modified to apply to a test for view serializability. • The problem of checking if a schedule is view serializable falls in the class of NP -complete problems. Thus existence of an efficient algorithm is unlikely. However practical algorithms that just check some sufficient conditions for view serializability can still be used.