SlideShare a Scribd company logo
1 of 29
Download to read offline
Database Management Systems
Transactions
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Transactions
▸ A collection of several operations on the database appears to be a single unit from the point of view of the database user.
For example, a transfer of funds from a checking account to a savings account is a single operation from the customer’s
standpoint; within the database system, however it consists of several operations. It is essential that all these operations
occur, or that, in case of a failure, none occur.
▸ Collections of operations that form a single logical unit of work are called transactions.
A database system
- must ensure proper execution of transactions despite failures either the entire transaction executes, or none of it does.
- must manage concurrent execution of transactions that avoids inconsistency.
▸ A transaction is a unit of program execution that accesses and possibly updates various data items.
▸ Usually, a transaction is initiated by a user program written in a high-level data-manipulation language (typically SQL), or
programming language (e.g. C++ or Java), with embedded database accesses in JDBC or ODBC.
▸ A transaction is delimited by statements (or function calls) of the form begin transaction and end transaction. The
transaction consists of all operations executed between the begin transaction and end transaction.
2
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Transaction Properties – ACID
▸ Atomicity – Either all operations of the transaction are reflected properly in the database, or none are.
▸ Consistency – Execution of a transaction atomically in isolation preserves the consistency (both data integrity constraints
and application-dependent constraints) of the database.
▸ Isolation – Even a single SQL statement involves many separate accesses to the database, and a transaction may
consist of several SQL statements. Therefore, the database system must take special actions to ensure that transactions
operate properly without interference from concurrently executing database statements. The system must guarantee
that, 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. Thus, each transaction is unaware of other transactions executing concurrently in the system.
▸ Durability – After a transaction completes successfully, the changes it has made to the database persist, even if there are
system failures.
3
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Transaction Model
▸ As SQL is a powerful and complex language, we begin with a simple database language that focuses on when the data
are moved from disk to main memory and from main memory to disk.
▸ The data items in our simplified model contain a single data value and each data item is identified by a name (ex. A, B, X
etc.)
▸ Transactions access data using two operations:
read(X) : transfers the data item X from the database to a variable, also called X, in a buffer in main memory belonging to
the transaction that executed the read operation.
write(X) : transfers the value in the variable X in the main-memory buffer of the transaction that executed the write to the
data item X in the database.
▸ Let, Ti be a transaction that transfers $50 from account A to account B. This transaction can be defined as:
1. read(A);
2. A := A – 50;
3. write(A);
4. read(B);
5. B := B + 50;
6. write(B);
4
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Let, Ti be a transaction that transfers $50 from account A to account B. This transaction can be defined as:
1. read(A);
2. A := A – 50;
3. write(A);
4. read(B);
5. B := B + 50;
6. write(B);
Transaction Properties – ACID
5
A = Atomicity
• If the transaction fails after step 3 and before step 6, money will be lost leading to an
inconsistent database state. Failure could be due to software or hardware.
• The system should ensure that updates of a partially executed transaction are not
reflected in the database.
• The basic idea behind ensuring atomicity is: The database system keeps track (on
disk) of the old values of any data on which a transaction performs a write. This
information is written to a file called the log.
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Let, Ti be a transaction that transfers $50 from account A to account B. This transaction can be defined as:
1. read(A);
2. A := A – 50;
3. write(A);
4. read(B);
5. B := B + 50;
6. write(B);
Transaction Properties – ACID
6
D = Durability
• Once the user has been notified that the transaction has completed the updates to the
database, it must be the case that no system failure can result in a loss of data
corresponding to this transaction.
• We can guarantee durability by ensuring any of the following:
i) The updates carried out by the transaction have been written to disk before the
transaction completes.
ii) Information about the updates carried out by the transaction is written to disk, and
such information is sufficient to enable that database to reconstruct the updates when
the database system is restarted after the failure.
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Let, Ti be a transaction that transfers $50 from account A to account B. This transaction can be defined as:
1. read(A);
2. A := A – 50;
3. write(A);
4. read(B);
5. B := B + 50;
6. write(B);
Transaction Properties – ACID
7
C = Consistency
• In general consistency requirements are of 2 kinds:
i) Explicit integrity constraints such as primary keys and foreign keys
ii) Implicit integrity constrains such as the sum of A and B is unchanged by the
execution of the transaction Ti
• A transaction when starting to execute must see a consistent database.
During transaction execution the database may be temporarily inconsistent.
When the transaction completes successfully the database must be consistent.
• Ensuring consistency for an individual transaction is the responsibility of the
application programmer who codes the transaction. This task may be facilitated by
automatic testing of integrity constraints.
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Transaction Properties – ACID
I = Isolation
▸ Even if the consistency and atomicity properties are ensured for each transaction, if several transactions are executed
concurrently, their operations may interleave in some undesirable way, resulting in an inconsistent state.
▸ The isolation property of a transaction ensures that the concurrent execution of transactions results in a system state
that is equivalent to a state that could have been obtained if these transactions executed one at a time in some order.
▸ If between steps 3 and 6 (of the fund transfer transaction), another transaction T2 is allowed to access the partially
updated database, it will see an inconsistent database (the sum A + B will be less than it should be).
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)
▸ A way to avoid the problem of concurrently executing transactions is to execute transactions serially (i.e. one after the
other). However, executing multiple transactions concurrently has significant benefits.
8
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Transaction States
9
Active – The initial state; the transaction stays in this state while it is
executing.
Partially committed –After the final statement has been executed. At
this point the transaction has completed its execution, but it is still
possible that it may have to be aborted, since the actual output may
still be temporarily residing in main memory, and thus a hardware
failure may preclude its successful completion.
Failed – After the discovery that normal execution can no longer
proceed with its normal execution.
Aborted –After the transaction has been rolled back, then it enters
the aborted state. Two options after it has been aborted:
i. restart the transaction for hardware or software error.
ii. kill the transaction for logical error
Committed – After successful completion
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Concurrent Execution
Transaction-processing systems usually allow multiple transactions to run concurrently.
Advantages are:
▸ Improved throughput and resource utilization: The parallelism of the CPU and I/O system can therefore be exploited to
run multiple transactions in parallel. While a read or write on behalf of one transaction is in progress on one disk,
another transaction can be running in the CPU, while another disk may be executing a read/write on behalf of 3rd
transactions.
▸ Reduced average response time: short transactions need not wait behind long ones. If the transactions are operating on
different parts of the database, it is better to let them run concurrently, sharing the CPU cycles and disk accesses
among them.
10
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Schedule & Serial Schedule
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.
Serial Schedule
Each serial schedule is a schedule that consists of a sequence of instructions from various transactions, where the
instructions belonging to one single transaction appear together in that schedule.
For a set of n transactions there exists n! different valid serial schedules but we can’t predict how many schedules are
possible in total (it depends on the OS and hardware).
11
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Schedule 1
▸ Let T1 transfer $50 from A to B, and T2 transfer 10% of
the balance from A to B.
▸ Initial balance:
A = 1000$ and
B = 2000$
▸ An example of a serial schedule in which T1 is followed
by T2 :
12
950
2050
855
2145
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Schedule 2
▸ Let T1 transfer $50 from A to B, and T2 transfer 10% of
the balance from A to B.
▸ Initial balance:
A = 1000$ and
B = 2000$
▸ An example of a serial schedule in which T2 is followed
by T1 :
13
850
2150
900
2100
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Schedule 3
▸ Let T1 transfer $50 from A to B, and T2 transfer 10% of
the balance from A to B.
▸ Initial balance:
A = 1000$ and
B = 2000$
▸ Let T1 and T2 be the transactions defined previously.
The following schedule is not a serial schedule, but it
is equivalent to Schedule 1.
▸ In schedule 1, 2 and 3 the sum ‘A+B’ is preserved.
14
950
2050
950
855
2050
2145
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Schedule 4
▸ Let T1 transfer $50 from A to B, and T2 transfer 10% of
the balance from A to B.
▸ Initial balance:
A = 1000$ and
B = 2000$
▸ The following concurrent schedule does not preserve
the sum of “A + B”
15
1000
950
1000
900
2100
2000
2050
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Serializability
16
▸ 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. With multiple transactions, the CPU time is shared among all the transactions.
▸ If control of concurrent execution is left entirely to the operating system, many possible schedules, including ones that
leave the database in an inconsistent state are possible. It is the job of 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.
▸ Serial schedules are serializable, but if steps of multiple transactions are interleaved, it is harder to determine whether a
schedule is serializable.
▸ 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:
▪ Conflict Serializability
▪ View Serializability
How to determine when a schedule is serializable!!!
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Conflicting Instructions
▸ Let li and lj be two Instructions of transactions Ti and Tj respectively. Instructions li and lj conflict if and only if there exists
some item Q accessed by both li and lj, and at least one of these instructions wrote Q.
▪ li = read(Q), lj = read(Q). li and lj don’t conflict.
▪ li = read(Q), lj = write(Q). They conflict.
▪ li = write(Q), lj = read(Q). They conflict.
▪ li = write(Q), lj = write(Q). They conflict.
▸ Intuitively, a conflict between li and lj forces a (logical) temporal order between them.
▪ If li and lj 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.
17
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Conflict Serializability
▸ 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
For example: Schedule S can be transformed into Schedule S’ that is serial. So, Schedule S is conflict serializable.
18
Schedule, S Conflict Serializable Schedule, S’
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Conflict Serializability
▸ 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
For example: Schedule S can not be transformed into a schedule that is serial. So, Schedule S is not conflict serializable.
19
Not conflict serializable schedule, S
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Precedence Graph
▸ A simple and efficient method for determining the conflict serializability of a schedule.
▸ Consider a schedule S. We construct a directed graph, called a precedence graph from S.
▸ This graph consists of a pair G=(V, E), where V is a set of vertices and E is a set of edges.
Here,
V consists of all the transactions participating in the schedule.
E consists of all edges Ti→Tj for which one of 3 conditions holds:
▪ Ti executes write(Q) before Tj executes read(Q)
▪ Ti executes read(Q) before Tj executes write(Q)
▪ Ti executes write(Q) before Tj executes write(Q)
▸ If an edge Ti → Tj exists in the precedence graph, then in any serial schedule S’ equivalent to S, Ti must appear before Tj
20
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Precedence Graph – Example 1
21
T1 T2
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Precedence Graph – Example 2
22
T2 T1
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Precedence Graph – Example 3
23
T1 T2
• If the precedence graph for S has a cycle, then the
schedule S is not conflict serializable.
• If the graph contains no cycles, then the schedule S
is conflict serializable.
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Serializability Order
24
▪ A serializability order of the transactions can be obtained by finding a linear order consistent with the partial order of
the precedence graph. This process is called topological sorting.
▪ There are, in general several possible linear orders that can be obtained through a topological sort.
Ti
Tk
Tj
Tm
Ti Tj Tk Tm
Ti Tk Tj Tm
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Conflict Serializability Check – 1
25
T1 T2
T3
T4
T5
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
Conflict Serializability Check – 2
26
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
T1 T2 T3 T4
Read(X)
Read(X)
Write(Y)
Read(Y)
Read(Y)
Write(X)
Read(W)
Write(Y)
Read(W)
Read(Z)
Write(W)
Read(Z)
Write(Z)
T1 T2
T3
T4
Serializability Order:
T1 → T3 → T4 → T1
or,
T1 → T2 → T3 → T4 → T1
Conflict Serializability Check – 3
27
Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
28
Simulator!!
https://devimam.github.io/dbtxn/
29
THANKS!
Any questions?
Email : imam@cse.uiu.ac.bd
Reference:
Database System Concepts by S. Sudarshan, Henry F. Korth, Abraham Silberschatz

More Related Content

What's hot

Log based and Recovery with concurrent transaction
Log based and Recovery with concurrent transactionLog based and Recovery with concurrent transaction
Log based and Recovery with concurrent transactionnikunjandy
 
Lecture 3 data structures and algorithms
Lecture 3 data structures and algorithmsLecture 3 data structures and algorithms
Lecture 3 data structures and algorithmsAakash deep Singhal
 
DBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaDBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaMohammad Imam Hossain
 
DBMS 6 | MySQL Practice List - Rank Related Queries
DBMS 6 | MySQL Practice List - Rank Related QueriesDBMS 6 | MySQL Practice List - Rank Related Queries
DBMS 6 | MySQL Practice List - Rank Related QueriesMohammad Imam Hossain
 
Relational Algebra & Calculus
Relational Algebra & CalculusRelational Algebra & Calculus
Relational Algebra & CalculusAbdullah Khosa
 
Transaction Processing Concept
Transaction Processing ConceptTransaction Processing Concept
Transaction Processing ConceptNishant Munjal
 
Sql queries questions and answers
Sql queries questions and answersSql queries questions and answers
Sql queries questions and answersMichael Belete
 
Fundamentals of Database system
Fundamentals of Database systemFundamentals of Database system
Fundamentals of Database systemphilipsinter
 
Database Management System
Database Management SystemDatabase Management System
Database Management SystemNANDINI SHARMA
 
10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
Stack organization
Stack organizationStack organization
Stack organizationchauhankapil
 
Recovery Techniques and Need of Recovery
Recovery Techniques and   Need of RecoveryRecovery Techniques and   Need of Recovery
Recovery Techniques and Need of RecoveryPooja Dixit
 
SQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankSQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankMd Mudassir
 

What's hot (20)

Log based and Recovery with concurrent transaction
Log based and Recovery with concurrent transactionLog based and Recovery with concurrent transaction
Log based and Recovery with concurrent transaction
 
Lecture 3 data structures and algorithms
Lecture 3 data structures and algorithmsLecture 3 data structures and algorithms
Lecture 3 data structures and algorithms
 
Database Chapter 1
Database Chapter 1Database Chapter 1
Database Chapter 1
 
Functional dependency
Functional dependencyFunctional dependency
Functional dependency
 
DBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaDBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR Schema
 
DBMS 6 | MySQL Practice List - Rank Related Queries
DBMS 6 | MySQL Practice List - Rank Related QueriesDBMS 6 | MySQL Practice List - Rank Related Queries
DBMS 6 | MySQL Practice List - Rank Related Queries
 
Relational Algebra & Calculus
Relational Algebra & CalculusRelational Algebra & Calculus
Relational Algebra & Calculus
 
Dependencies
DependenciesDependencies
Dependencies
 
Normalization
NormalizationNormalization
Normalization
 
Transaction Processing Concept
Transaction Processing ConceptTransaction Processing Concept
Transaction Processing Concept
 
Sql queries questions and answers
Sql queries questions and answersSql queries questions and answers
Sql queries questions and answers
 
Fundamentals of Database system
Fundamentals of Database systemFundamentals of Database system
Fundamentals of Database system
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
 
Database language
Database languageDatabase language
Database language
 
Databases: Normalisation
Databases: NormalisationDatabases: Normalisation
Databases: Normalisation
 
10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil
 
Stack organization
Stack organizationStack organization
Stack organization
 
Recovery Techniques and Need of Recovery
Recovery Techniques and   Need of RecoveryRecovery Techniques and   Need of Recovery
Recovery Techniques and Need of Recovery
 
Dbms notes
Dbms notesDbms notes
Dbms notes
 
SQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankSQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question Bank
 

Similar to Database Transactions Explained

Dartabase Transaction.pptx
Dartabase Transaction.pptxDartabase Transaction.pptx
Dartabase Transaction.pptxBibus Poudel
 
DBMS-chap 2-Concurrency Control
DBMS-chap 2-Concurrency ControlDBMS-chap 2-Concurrency Control
DBMS-chap 2-Concurrency ControlMukesh Tekwani
 
Dbms sixth chapter_part-1_2011
Dbms sixth chapter_part-1_2011Dbms sixth chapter_part-1_2011
Dbms sixth chapter_part-1_2011sumit_study
 
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...DrCViji
 
TRANSACTION MANAGEMENT AND TIME STAMP PROTOCOLS AND BACKUP RECOVERY
TRANSACTION MANAGEMENT AND TIME STAMP PROTOCOLS AND BACKUP RECOVERYTRANSACTION MANAGEMENT AND TIME STAMP PROTOCOLS AND BACKUP RECOVERY
TRANSACTION MANAGEMENT AND TIME STAMP PROTOCOLS AND BACKUP RECOVERYRohit Kumar
 
DBMS Unit III Material
DBMS Unit III MaterialDBMS Unit III Material
DBMS Unit III MaterialArthyR3
 
UNIT-IV: Transaction Processing Concepts
UNIT-IV: Transaction Processing ConceptsUNIT-IV: Transaction Processing Concepts
UNIT-IV: Transaction Processing ConceptsRaj vardhan
 
Transactions in dbms
Transactions in dbmsTransactions in dbms
Transactions in dbmsNancy Gulati
 
Transaction processing ppt
Transaction processing pptTransaction processing ppt
Transaction processing pptJaved Khan
 
Transaction slide
Transaction slideTransaction slide
Transaction slideshawon roy
 
Optimistic concurrency control in Distributed Systems
Optimistic concurrency control in Distributed SystemsOptimistic concurrency control in Distributed Systems
Optimistic concurrency control in Distributed Systemsmridul mishra
 
Introduction to transaction processing concepts and theory
Introduction to transaction processing concepts and theoryIntroduction to transaction processing concepts and theory
Introduction to transaction processing concepts and theoryZainab Almugbel
 
Concurrency control
Concurrency  controlConcurrency  control
Concurrency controlJaved Khan
 

Similar to Database Transactions Explained (20)

Dartabase Transaction.pptx
Dartabase Transaction.pptxDartabase Transaction.pptx
Dartabase Transaction.pptx
 
DBMS-chap 2-Concurrency Control
DBMS-chap 2-Concurrency ControlDBMS-chap 2-Concurrency Control
DBMS-chap 2-Concurrency Control
 
Dbms sixth chapter_part-1_2011
Dbms sixth chapter_part-1_2011Dbms sixth chapter_part-1_2011
Dbms sixth chapter_part-1_2011
 
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...
 
Ch15
Ch15Ch15
Ch15
 
DBMS UNIT 4
DBMS UNIT 4DBMS UNIT 4
DBMS UNIT 4
 
Unit06 dbms
Unit06 dbmsUnit06 dbms
Unit06 dbms
 
Tybsc cs dbms2 notes
Tybsc cs dbms2 notesTybsc cs dbms2 notes
Tybsc cs dbms2 notes
 
24904 lecture11
24904 lecture1124904 lecture11
24904 lecture11
 
TRANSACTION MANAGEMENT AND TIME STAMP PROTOCOLS AND BACKUP RECOVERY
TRANSACTION MANAGEMENT AND TIME STAMP PROTOCOLS AND BACKUP RECOVERYTRANSACTION MANAGEMENT AND TIME STAMP PROTOCOLS AND BACKUP RECOVERY
TRANSACTION MANAGEMENT AND TIME STAMP PROTOCOLS AND BACKUP RECOVERY
 
DBMS Unit III Material
DBMS Unit III MaterialDBMS Unit III Material
DBMS Unit III Material
 
UNIT-IV: Transaction Processing Concepts
UNIT-IV: Transaction Processing ConceptsUNIT-IV: Transaction Processing Concepts
UNIT-IV: Transaction Processing Concepts
 
Transactions in dbms
Transactions in dbmsTransactions in dbms
Transactions in dbms
 
Transaction processing ppt
Transaction processing pptTransaction processing ppt
Transaction processing ppt
 
Transaction slide
Transaction slideTransaction slide
Transaction slide
 
Optimistic concurrency control in Distributed Systems
Optimistic concurrency control in Distributed SystemsOptimistic concurrency control in Distributed Systems
Optimistic concurrency control in Distributed Systems
 
Introduction to transaction processing concepts and theory
Introduction to transaction processing concepts and theoryIntroduction to transaction processing concepts and theory
Introduction to transaction processing concepts and theory
 
Chapter 4 u
Chapter 4 uChapter 4 u
Chapter 4 u
 
Concurrency control
Concurrency  controlConcurrency  control
Concurrency control
 
Dbms
DbmsDbms
Dbms
 

More from Mohammad Imam Hossain

DS & Algo 4 - Graph and Shortest Path Search
DS & Algo 4 - Graph and Shortest Path SearchDS & Algo 4 - Graph and Shortest Path Search
DS & Algo 4 - Graph and Shortest Path SearchMohammad Imam Hossain
 
DS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL IntroductionDS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL IntroductionMohammad Imam Hossain
 
TOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity CheckTOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity CheckMohammad Imam Hossain
 
TOC 4 | Non-deterministic Finite Automata
TOC 4 | Non-deterministic Finite AutomataTOC 4 | Non-deterministic Finite Automata
TOC 4 | Non-deterministic Finite AutomataMohammad Imam Hossain
 
TOC 2 | Deterministic Finite Automata
TOC 2 | Deterministic Finite AutomataTOC 2 | Deterministic Finite Automata
TOC 2 | Deterministic Finite AutomataMohammad Imam Hossain
 

More from Mohammad Imam Hossain (20)

DS & Algo 6 - Offline Assignment 6
DS & Algo 6 - Offline Assignment 6DS & Algo 6 - Offline Assignment 6
DS & Algo 6 - Offline Assignment 6
 
DS & Algo 6 - Dynamic Programming
DS & Algo 6 - Dynamic ProgrammingDS & Algo 6 - Dynamic Programming
DS & Algo 6 - Dynamic Programming
 
DS & Algo 5 - Disjoint Set and MST
DS & Algo 5 - Disjoint Set and MSTDS & Algo 5 - Disjoint Set and MST
DS & Algo 5 - Disjoint Set and MST
 
DS & Algo 4 - Graph and Shortest Path Search
DS & Algo 4 - Graph and Shortest Path SearchDS & Algo 4 - Graph and Shortest Path Search
DS & Algo 4 - Graph and Shortest Path Search
 
DS & Algo 3 - Offline Assignment 3
DS & Algo 3 - Offline Assignment 3DS & Algo 3 - Offline Assignment 3
DS & Algo 3 - Offline Assignment 3
 
DS & Algo 3 - Divide and Conquer
DS & Algo 3 - Divide and ConquerDS & Algo 3 - Divide and Conquer
DS & Algo 3 - Divide and Conquer
 
DS & Algo 2 - Offline Assignment 2
DS & Algo 2 - Offline Assignment 2DS & Algo 2 - Offline Assignment 2
DS & Algo 2 - Offline Assignment 2
 
DS & Algo 2 - Recursion
DS & Algo 2 - RecursionDS & Algo 2 - Recursion
DS & Algo 2 - Recursion
 
DS & Algo 1 - Offline Assignment 1
DS & Algo 1 - Offline Assignment 1DS & Algo 1 - Offline Assignment 1
DS & Algo 1 - Offline Assignment 1
 
DS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL IntroductionDS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL Introduction
 
DBMS 7 | Relational Query Language
DBMS 7 | Relational Query LanguageDBMS 7 | Relational Query Language
DBMS 7 | Relational Query Language
 
TOC 10 | Turing Machine
TOC 10 | Turing MachineTOC 10 | Turing Machine
TOC 10 | Turing Machine
 
TOC 9 | Pushdown Automata
TOC 9 | Pushdown AutomataTOC 9 | Pushdown Automata
TOC 9 | Pushdown Automata
 
TOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity CheckTOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity Check
 
TOC 7 | CFG in Chomsky Normal Form
TOC 7 | CFG in Chomsky Normal FormTOC 7 | CFG in Chomsky Normal Form
TOC 7 | CFG in Chomsky Normal Form
 
TOC 6 | CFG Design
TOC 6 | CFG DesignTOC 6 | CFG Design
TOC 6 | CFG Design
 
TOC 5 | Regular Expressions
TOC 5 | Regular ExpressionsTOC 5 | Regular Expressions
TOC 5 | Regular Expressions
 
TOC 4 | Non-deterministic Finite Automata
TOC 4 | Non-deterministic Finite AutomataTOC 4 | Non-deterministic Finite Automata
TOC 4 | Non-deterministic Finite Automata
 
TOC 3 | Different Operations on DFA
TOC 3 | Different Operations on DFATOC 3 | Different Operations on DFA
TOC 3 | Different Operations on DFA
 
TOC 2 | Deterministic Finite Automata
TOC 2 | Deterministic Finite AutomataTOC 2 | Deterministic Finite Automata
TOC 2 | Deterministic Finite Automata
 

Recently uploaded

KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 

Recently uploaded (20)

KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 

Database Transactions Explained

  • 1. Database Management Systems Transactions Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 2. Transactions ▸ A collection of several operations on the database appears to be a single unit from the point of view of the database user. For example, a transfer of funds from a checking account to a savings account is a single operation from the customer’s standpoint; within the database system, however it consists of several operations. It is essential that all these operations occur, or that, in case of a failure, none occur. ▸ Collections of operations that form a single logical unit of work are called transactions. A database system - must ensure proper execution of transactions despite failures either the entire transaction executes, or none of it does. - must manage concurrent execution of transactions that avoids inconsistency. ▸ A transaction is a unit of program execution that accesses and possibly updates various data items. ▸ Usually, a transaction is initiated by a user program written in a high-level data-manipulation language (typically SQL), or programming language (e.g. C++ or Java), with embedded database accesses in JDBC or ODBC. ▸ A transaction is delimited by statements (or function calls) of the form begin transaction and end transaction. The transaction consists of all operations executed between the begin transaction and end transaction. 2 Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 3. Transaction Properties – ACID ▸ Atomicity – Either all operations of the transaction are reflected properly in the database, or none are. ▸ Consistency – Execution of a transaction atomically in isolation preserves the consistency (both data integrity constraints and application-dependent constraints) of the database. ▸ Isolation – Even a single SQL statement involves many separate accesses to the database, and a transaction may consist of several SQL statements. Therefore, the database system must take special actions to ensure that transactions operate properly without interference from concurrently executing database statements. The system must guarantee that, 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. Thus, each transaction is unaware of other transactions executing concurrently in the system. ▸ Durability – After a transaction completes successfully, the changes it has made to the database persist, even if there are system failures. 3 Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 4. Transaction Model ▸ As SQL is a powerful and complex language, we begin with a simple database language that focuses on when the data are moved from disk to main memory and from main memory to disk. ▸ The data items in our simplified model contain a single data value and each data item is identified by a name (ex. A, B, X etc.) ▸ Transactions access data using two operations: read(X) : transfers the data item X from the database to a variable, also called X, in a buffer in main memory belonging to the transaction that executed the read operation. write(X) : transfers the value in the variable X in the main-memory buffer of the transaction that executed the write to the data item X in the database. ▸ Let, Ti be a transaction that transfers $50 from account A to account B. This transaction can be defined as: 1. read(A); 2. A := A – 50; 3. write(A); 4. read(B); 5. B := B + 50; 6. write(B); 4 Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 5. Let, Ti be a transaction that transfers $50 from account A to account B. This transaction can be defined as: 1. read(A); 2. A := A – 50; 3. write(A); 4. read(B); 5. B := B + 50; 6. write(B); Transaction Properties – ACID 5 A = Atomicity • If the transaction fails after step 3 and before step 6, money will be lost leading to an inconsistent database state. Failure could be due to software or hardware. • The system should ensure that updates of a partially executed transaction are not reflected in the database. • The basic idea behind ensuring atomicity is: The database system keeps track (on disk) of the old values of any data on which a transaction performs a write. This information is written to a file called the log. Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 6. Let, Ti be a transaction that transfers $50 from account A to account B. This transaction can be defined as: 1. read(A); 2. A := A – 50; 3. write(A); 4. read(B); 5. B := B + 50; 6. write(B); Transaction Properties – ACID 6 D = Durability • Once the user has been notified that the transaction has completed the updates to the database, it must be the case that no system failure can result in a loss of data corresponding to this transaction. • We can guarantee durability by ensuring any of the following: i) The updates carried out by the transaction have been written to disk before the transaction completes. ii) Information about the updates carried out by the transaction is written to disk, and such information is sufficient to enable that database to reconstruct the updates when the database system is restarted after the failure. Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 7. Let, Ti be a transaction that transfers $50 from account A to account B. This transaction can be defined as: 1. read(A); 2. A := A – 50; 3. write(A); 4. read(B); 5. B := B + 50; 6. write(B); Transaction Properties – ACID 7 C = Consistency • In general consistency requirements are of 2 kinds: i) Explicit integrity constraints such as primary keys and foreign keys ii) Implicit integrity constrains such as the sum of A and B is unchanged by the execution of the transaction Ti • A transaction when starting to execute must see a consistent database. During transaction execution the database may be temporarily inconsistent. When the transaction completes successfully the database must be consistent. • Ensuring consistency for an individual transaction is the responsibility of the application programmer who codes the transaction. This task may be facilitated by automatic testing of integrity constraints. Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 8. Transaction Properties – ACID I = Isolation ▸ Even if the consistency and atomicity properties are ensured for each transaction, if several transactions are executed concurrently, their operations may interleave in some undesirable way, resulting in an inconsistent state. ▸ The isolation property of a transaction ensures that the concurrent execution of transactions results in a system state that is equivalent to a state that could have been obtained if these transactions executed one at a time in some order. ▸ If between steps 3 and 6 (of the fund transfer transaction), another transaction T2 is allowed to access the partially updated database, it will see an inconsistent database (the sum A + B will be less than it should be). 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) ▸ A way to avoid the problem of concurrently executing transactions is to execute transactions serially (i.e. one after the other). However, executing multiple transactions concurrently has significant benefits. 8 Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 9. Transaction States 9 Active – The initial state; the transaction stays in this state while it is executing. Partially committed –After the final statement has been executed. At this point the transaction has completed its execution, but it is still possible that it may have to be aborted, since the actual output may still be temporarily residing in main memory, and thus a hardware failure may preclude its successful completion. Failed – After the discovery that normal execution can no longer proceed with its normal execution. Aborted –After the transaction has been rolled back, then it enters the aborted state. Two options after it has been aborted: i. restart the transaction for hardware or software error. ii. kill the transaction for logical error Committed – After successful completion Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 10. Concurrent Execution Transaction-processing systems usually allow multiple transactions to run concurrently. Advantages are: ▸ Improved throughput and resource utilization: The parallelism of the CPU and I/O system can therefore be exploited to run multiple transactions in parallel. While a read or write on behalf of one transaction is in progress on one disk, another transaction can be running in the CPU, while another disk may be executing a read/write on behalf of 3rd transactions. ▸ Reduced average response time: short transactions need not wait behind long ones. If the transactions are operating on different parts of the database, it is better to let them run concurrently, sharing the CPU cycles and disk accesses among them. 10 Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 11. Schedule & Serial Schedule 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. Serial Schedule Each serial schedule is a schedule that consists of a sequence of instructions from various transactions, where the instructions belonging to one single transaction appear together in that schedule. For a set of n transactions there exists n! different valid serial schedules but we can’t predict how many schedules are possible in total (it depends on the OS and hardware). 11 Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 12. Schedule 1 ▸ Let T1 transfer $50 from A to B, and T2 transfer 10% of the balance from A to B. ▸ Initial balance: A = 1000$ and B = 2000$ ▸ An example of a serial schedule in which T1 is followed by T2 : 12 950 2050 855 2145 Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 13. Schedule 2 ▸ Let T1 transfer $50 from A to B, and T2 transfer 10% of the balance from A to B. ▸ Initial balance: A = 1000$ and B = 2000$ ▸ An example of a serial schedule in which T2 is followed by T1 : 13 850 2150 900 2100 Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 14. Schedule 3 ▸ Let T1 transfer $50 from A to B, and T2 transfer 10% of the balance from A to B. ▸ Initial balance: A = 1000$ and B = 2000$ ▸ Let T1 and T2 be the transactions defined previously. The following schedule is not a serial schedule, but it is equivalent to Schedule 1. ▸ In schedule 1, 2 and 3 the sum ‘A+B’ is preserved. 14 950 2050 950 855 2050 2145 Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 15. Schedule 4 ▸ Let T1 transfer $50 from A to B, and T2 transfer 10% of the balance from A to B. ▸ Initial balance: A = 1000$ and B = 2000$ ▸ The following concurrent schedule does not preserve the sum of “A + B” 15 1000 950 1000 900 2100 2000 2050 Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 16. Serializability 16 ▸ 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. With multiple transactions, the CPU time is shared among all the transactions. ▸ If control of concurrent execution is left entirely to the operating system, many possible schedules, including ones that leave the database in an inconsistent state are possible. It is the job of 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. ▸ Serial schedules are serializable, but if steps of multiple transactions are interleaved, it is harder to determine whether a schedule is serializable. ▸ 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: ▪ Conflict Serializability ▪ View Serializability How to determine when a schedule is serializable!!! Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 17. Conflicting Instructions ▸ Let li and lj be two Instructions of transactions Ti and Tj respectively. Instructions li and lj conflict if and only if there exists some item Q accessed by both li and lj, and at least one of these instructions wrote Q. ▪ li = read(Q), lj = read(Q). li and lj don’t conflict. ▪ li = read(Q), lj = write(Q). They conflict. ▪ li = write(Q), lj = read(Q). They conflict. ▪ li = write(Q), lj = write(Q). They conflict. ▸ Intuitively, a conflict between li and lj forces a (logical) temporal order between them. ▪ If li and lj 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. 17 Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 18. Conflict Serializability ▸ 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 For example: Schedule S can be transformed into Schedule S’ that is serial. So, Schedule S is conflict serializable. 18 Schedule, S Conflict Serializable Schedule, S’ Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 19. Conflict Serializability ▸ 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 For example: Schedule S can not be transformed into a schedule that is serial. So, Schedule S is not conflict serializable. 19 Not conflict serializable schedule, S Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 20. Precedence Graph ▸ A simple and efficient method for determining the conflict serializability of a schedule. ▸ Consider a schedule S. We construct a directed graph, called a precedence graph from S. ▸ This graph consists of a pair G=(V, E), where V is a set of vertices and E is a set of edges. Here, V consists of all the transactions participating in the schedule. E consists of all edges Ti→Tj for which one of 3 conditions holds: ▪ Ti executes write(Q) before Tj executes read(Q) ▪ Ti executes read(Q) before Tj executes write(Q) ▪ Ti executes write(Q) before Tj executes write(Q) ▸ If an edge Ti → Tj exists in the precedence graph, then in any serial schedule S’ equivalent to S, Ti must appear before Tj 20 Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 21. Precedence Graph – Example 1 21 T1 T2 Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 22. Precedence Graph – Example 2 22 T2 T1 Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 23. Precedence Graph – Example 3 23 T1 T2 • If the precedence graph for S has a cycle, then the schedule S is not conflict serializable. • If the graph contains no cycles, then the schedule S is conflict serializable. Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 24. Serializability Order 24 ▪ A serializability order of the transactions can be obtained by finding a linear order consistent with the partial order of the precedence graph. This process is called topological sorting. ▪ There are, in general several possible linear orders that can be obtained through a topological sort. Ti Tk Tj Tm Ti Tj Tk Tm Ti Tk Tj Tm Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 25. Conflict Serializability Check – 1 25 T1 T2 T3 T4 T5 Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 26. Conflict Serializability Check – 2 26 Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU T1 T2 T3 T4 Read(X) Read(X) Write(Y) Read(Y) Read(Y) Write(X) Read(W) Write(Y) Read(W) Read(Z) Write(W) Read(Z) Write(Z) T1 T2 T3 T4 Serializability Order: T1 → T3 → T4 → T1 or, T1 → T2 → T3 → T4 → T1
  • 27. Conflict Serializability Check – 3 27 Mohammad Imam Hossain, Lecturer, Dept. of CSE, UIU
  • 29. 29 THANKS! Any questions? Email : imam@cse.uiu.ac.bd Reference: Database System Concepts by S. Sudarshan, Henry F. Korth, Abraham Silberschatz