Database Management System ยท Unit 8 ยท 4 hrs
Introduction to Transaction Processing Concepts and Theory
Exam-focused notes for Introduction to Transaction Processing Concepts and Theory (Database Management System, CSC265): what the TU syllabus asks and how it has actually been tested, with 7 solved past questions from this unit.
Introduction to Transaction Processing Concepts and Theory in short
This unit introduces transaction processing theory: what a transaction is at the level of individual reads and writes, the properties every transaction should have, and the two formal lenses, recoverability and serializability, used to judge whether an interleaved schedule of several transactions is safe to run at all.
What this unit covers
- Introduction to Transaction Processing
- Transaction and System Concepts
- Desirable Properties of Transactions
- Characterizing Schedules Based on Recoverability
- Characterizing Schedules Based on Serializability
Desirable Properties of Transactions
2080 ยท 5 marks
Define transaction. What are different desirable properties of transaction. [5]
Characterizing Schedules Based on Serializability
2079 ยท 5 marks
What is conflict schedule? Explain with example. [5]
Show solved answerHide answer
Conflict Schedule
Definition
A conflict schedule (more precisely, a schedule with conflicting operations) refers to a schedule in which two or more transactions contain conflicting operations. Two operations in a schedule are said to conflict if they satisfy all three of the following conditions:
- They belong to different transactions.
- They access the same data item X.
- At least one of them is a write operation.
The possible conflicting pairs are:
| Operation Pair | Conflict? |
|---|---|
| Read(X) and Read(X) | No |
| Read(X) and Write(X) | Yes |
| Write(X) and Read(X) | Yes |
| Write(X) and Write(X) | Yes |
Conflict Serializability
A schedule is called conflict serializable if it can be transformed into a serial schedule by swapping non-conflicting operations. To test this, a precedence graph (serialization graph) is constructed.
Algorithm (from notes):
- Look at only
read_Item(X)andwrite_Item(X)operations. - Construct a precedence graph with directed edges.
- Draw an edge from Ti โ Tj if an operation in Ti appears before a conflicting operation in Tj.
- The schedule is conflict serializable if and only if the precedence graph has no cycles.
Example
Consider two transactions:
- T1: read(X), write(X), read(Y), write(Y)
- T2: read(X), write(X), read(Y), write(Y)
Schedule S:
| Step | Operation |
|---|---|
| 1 | T1: read(X) |
| 2 | T2: read(X) |
| 3 | T1: write(X) |
| 4 | T2: write(X) |
| 5 | T1: read(Y) |
| 6 | T2: read(Y) |
| 7 | T1: write(Y) |
| 8 | T2: write(Y) |
Identifying Conflicts:
Every pair below is on the same data item, from different transactions, with at least one write, so each pair contributes an edge in the direction of the operation that comes first in the schedule.
| Conflict | Reason |
|---|---|
| T1:read(X) at step 1 and T2:write(X) at step 4 | T1 reads X before T2 writes it โ T1 โ T2 |
| T2:read(X) at step 2 and T1:write(X) at step 3 | T2 reads X before T1 writes it โ T2 โ T1 |
| T1:write(X) at step 3 and T2:write(X) at step 4 | Both write X, T1 first โ T1 โ T2 |
| T1:read(Y) at step 5 and T2:write(Y) at step 8 | T1 reads Y before T2 writes it โ T1 โ T2 |
| T2:read(Y) at step 6 and T1:write(Y) at step 7 | T2 reads Y before T1 writes it โ T2 โ T1 |
| T1:write(Y) at step 7 and T2:write(Y) at step 8 | Both write Y, T1 first โ T1 โ T2 |
Precedence Graph:
T1 ---------> T2
^ |
|____________|
- Edges run in both directions, so the graph contains a cycle (T1 โ T2 โ T1).
- Therefore, Schedule S is NOT conflict serializable. Neither serial order works: T2 reads X before T1 writes it, which would put T2 first, while T1 writes X before T2 writes it, which would put T1 first.
A Conflict Serializable Schedule S1:
Interleaving the same two transactions differently gives a schedule that is conflict serializable.
| Step | Operation |
|---|---|
| 1 | T1: read(X) |
| 2 | T1: write(X) |
| 3 | T2: read(X) |
| 4 | T1: read(Y) |
| 5 | T2: write(X) |
| 6 | T1: write(Y) |
| 7 | T2: read(Y) |
| 8 | T2: write(Y) |
Here every conflicting pair has the T1 operation first: read(X) of T1 before write(X) of T2, write(X) of T1 before both read(X) and write(X) of T2, read(Y) of T1 before write(Y) of T2, and write(Y) of T1 before both read(Y) and write(Y) of T2.
Precedence Graph:
T1 ---------> T2
- There is no cycle in this precedence graph.
- Therefore, Schedule S1 is conflict serializable, equivalent to the serial schedule T1 โ T2, even though its operations are interleaved.
Example of a NON-Conflict Serializable Schedule
Schedule S2:
| Step | Operation |
|---|---|
| 1 | T1: read(X) |
| 2 | T2: write(X) |
| 3 | T1: write(X) |
| 4 | T2: read(Y) |
| 5 | T1: write(Y) |
| 6 | T2: write(Y) |
Conflicts:
- T2:write(X) before T1:write(X) โ T2 โ T1
- T1:write(Y) before T2:write(Y) โ T1 โ T2
Precedence Graph:
T1 ---------> T2
^ |
|____________|
- There is a cycle (T1 โ T2 โ T1).
- Therefore, Schedule S2 is NOT conflict serializable.
Summary
A conflict schedule contains conflicting operations (same data item, different transactions, at least one write). It is conflict serializable if its precedence graph contains no cycle, meaning it is equivalent to some serial execution of the transactions.
2078 ยท 5 marks
Define schedule and serializability. How can you test the serializability? [5]
Show solved answerHide answer
Schedule and Serializability
Schedule
A schedule (also called a history) is an ordering of the operations from a set of concurrent transactions, where the operations of each individual transaction appear in the same order as they do in that transaction. A schedule defines the interleaved execution sequence of operations (read, write, commit, abort) from multiple transactions.
Types of Schedules:
- Serial Schedule: Transactions execute one after another with no interleaving. If there are n transactions, there are n! possible serial schedules.
- Non-Serial (Concurrent) Schedule: Operations from multiple transactions are interleaved.
Serializability
A concurrent schedule is said to be serializable if its final result (effect on the database) is totally the same as the final result produced by some serial schedule of the same transactions. In other words, even though transactions execute concurrently with interleaved operations, the outcome must be equivalent to some sequential (serial) execution.
Serializability ensures correctness of concurrent execution while maximizing resource utilization and efficiency.
Types of Serializability
-
Conflict Serializability: A schedule is conflict serializable if it can be transformed into a serial schedule by swapping non-conflicting operations.
-
View Serializability: A schedule is view serializable if its view equals that of a serial schedule (no overlapping transactions). Every conflict serializable schedule is view serializable, but if a schedule contains blind writes, it may be view serializable without being conflict serializable.
Testing for Serializability (Precedence Graph Method)
The standard method to test conflict serializability uses a Precedence Graph (also called a Serialization Graph):
Algorithm:
-
Consider only
read_Item(X)andwrite_Item(X)operations from the schedule. -
Construct a Precedence Graph:
- Nodes represent each transaction T1, T2, ..., Tn.
- A directed edge is drawn from Ti โ Tj if an operation in Ti appears before a conflicting operation in Tj.
-
Conflicting operations occur when:
- Two transactions access the same data item X, AND
- At least one of them is a write operation.
- Cases: read(X) then write(X), write(X) then read(X), write(X) then write(X).
-
Check for cycles:
- If the precedence graph has no cycle โ the schedule is conflict serializable.
- If the precedence graph has a cycle โ the schedule is NOT serializable.
Example:
| Step | T1 | T2 |
|---|---|---|
| 1 | read(X) | |
| 2 | read(X) | |
| 3 | write(X) | |
| 4 | write(X) |
- T1 writes X before T2 writes X โ edge T1 โ T2
- T1 reads X before T2 writes X โ edge T1 โ T2
- T2 reads X before T1 writes X โ edge T2 โ T1
This creates a cycle (T1 โ T2 โ T1), so the schedule is NOT serializable.
Summary: Serializability is the key correctness criterion for concurrent transaction execution in DBMS. The precedence graph (no cycle = serializable) is the standard test for conflict serializability.
2076 ยท 5 marks
Define schedule and serializability. How can you test the serializability? [5]
Show solved answerHide answer
Schedule and Serializability
Schedule
A schedule (also called a history) is an ordering of the operations from a set of concurrent transactions, where the operations of each individual transaction appear in the same order as they do in that transaction. A schedule defines the sequence in which operations (read, write, commit, abort) from multiple transactions are interleaved and executed by the DBMS.
Example: If T1 and T2 are two transactions, a possible schedule S could be:
S: R1(X) โ R2(X) โ W1(X) โ W2(X)
Serializability
A concurrent schedule is said to be serializable if its final result (effect on the database) is totally the same as the final result produced by some serial schedule (where transactions execute one after another without interleaving).
Since serial schedules are always considered correct (no concurrency issues), any serializable schedule is also considered correct.
There are two types of serializable schedules:
1. Conflict Serializable
A schedule is conflict serializable if it can be transformed into a serial schedule by swapping non-conflicting operations.
2. View Serializable
A schedule is called view serializable if its view equals that of a serial schedule (no overlapping transactions). A conflict serializable schedule is always view serializable, but if the schedule contains blind writes, it may be view serializable without being conflict serializable.
Testing for Serializability (Precedence Graph Method)
The most common method to test conflict serializability uses a Precedence Graph (also called a serialization graph).
Algorithm:
- Look at only
read_Item(X)andwrite_Item(X)operations in the schedule. - Construct a precedence graph -- a directed graph where each transaction Ti is a node.
- Draw a directed edge from Ti to Tj if one of the operations in Ti appears before a conflicting operation in Tj. Two operations conflict if:
- They belong to different transactions
- They access the same data item X
- At least one of them is a write
- The schedule is conflict serializable if and only if the precedence graph has NO cycles.
Example:
Consider Schedule S with transactions T1 and T2:
S: R1(X) โ W2(X) โ W1(X) โ R2(Y) โ W2(Y)
| Conflict Detected | Edge |
|---|---|
| R1(X) before W2(X) | T1 โ T2 |
| W2(X) before W1(X) | T2 โ T1 |
Precedence Graph:
T1 -----> T2
T2 -----> T1 (CYCLE EXISTS)
Since a cycle exists, this schedule is NOT conflict serializable.
Summary Table
| Property | Meaning |
|---|---|
| Serial Schedule | Transactions execute one after another (always correct) |
| Serializable Schedule | Equivalent in result to some serial schedule |
| Test Method | Precedence graph -- no cycle = serializable |
Transaction and System Concepts
2079 ยท 5 marks
What is transaction? Draw states of transaction and explain. [5]
Characterizing Schedules Based on Recoverability
2080.1 ยท 5 marks
Explain schedule based on recoverability and serializability. [5]
Introduction to Transaction Processing
2080.1 ยท 5 marks
Write short notes on: a. Transaction processing b. Weak entity [5]
Make Unit 8 stick
Practice CSC265 with flashcards & quizzes