- DBMS - Home
- DBMS - Overview
- DBMS - Architecture
- DBMS - Data Models
- DBMS - Data Schemas
- DBMS - Data Independence
- DBMS - System Environment
- Centralized and Client/Server Architecture
- DBMS - Classification
- Relational Model
- DBMS - Codd's Rules
- DBMS - Relational Data Model
- DBMS - Relational Model Constraints
- DBMS - Relational Database Schemas
- DBMS - Handling Constraint Violations
- Entity Relationship Model
- DBMS - ER Model Basic Concepts
- DBMS - ER Diagram Representation
- Relationship Types and Relationship Sets
- DBMS - Weak Entity Types
- DBMS - Generalization, Aggregation
- DBMS - Drawing an ER Diagram
- DBMS - Enhanced ER Model
- Subclass, Superclass and Inheritance in EER
- Specialization and Generalization in Extended ER Model
- Data Abstraction and Knowledge Representation
- Relational Algebra
- DBMS - Relational Algebra
- Unary Relational Operation
- Set Theory Operations
- DBMS - Database Joins
- DBMS - Division Operation
- DBMS - ER to Relational Model
- Examples of Query in Relational Algebra
- Relational Calculus
- Tuple Relational Calculus
- Domain Relational Calculus
- Relational Database Design
- DBMS - Functional Dependency
- DBMS - Inference Rules
- DBMS - Minimal Cover
- Equivalence of Functional Dependency
- Finding Attribute Closure and Candidate Keys
- Relational Database Design
- DBMS - Keys
- Super keys and candidate keys
- DBMS - Foreign Key
- Finding Candidate Keys
- Normalization in Database Designing
- Database Normalization
- First Normal Form
- Second Normal Form
- Third Normal Form
- Boyce Codd Normal Form
- Difference Between 4NF and 5NF
- Structured Query Language
- Types of Languages in SQL
- Querying in SQL
- CRUD Operations in SQL
- Aggregation Function in SQL
- Join and Subquery in SQL
- Views in SQL
- Trigger and Schema Modification
- Storage and File Structure
- DBMS - Storage System
- DBMS - File Structure
- DBMS - Secondary Storage Devices
- DBMS - Buffer and Disk Blocks
- DBMS - Placing File Records on Disk
- DBMS - Ordered and Unordered Records
- Indexing and Hashing
- DBMS - Indexing
- DBMS - Single-Level Ordered Indexing
- DBMS - Multi-level Indexing
- Dynamic B- Tree and B+ Tree
- DBMS - Hashing
- Query Processing and Optimization
- Heuristics in Query Processing
- Transaction and Concurrency
- DBMS - Transaction
- DBMS - Scheduling Transactions
- DBMS - Testing Serializability
- DBMS - Conflict Serializability
- DBMS - View Serializability
- DBMS - Concurrency Control
- DBMS - Lock Based Protocol
- DBMS - Timestamping based Protocol
- DBMS - Phantom Read Problem
- DBMS - Dirty Read Problem
- DBMS - Thomas Write Rule
- DBMS - Deadlock
- Backup and Recovery
- DBMS - Data Backup
- DBMS - Data Recovery
- DBMS Useful Resources
- DBMS - Quick Guide
- DBMS - Useful Resources
- DBMS - Discussion
DBMS - Scheduling in Transactions
Transactions ensure that data remains accurate and consistent even when multiple processes run simultaneously. There may be more than one transactions in action. But when several transactions are executed together, how do we organize them without creating data conflicts? Here the concept of "scheduling" comes. Read this chapter to learn the basics of scheduling, its types, and examples for a better understanding.
What is Scheduling?
A schedule is an ordered sequence of operations from different transactions arranged based on their execution order or timeline. A schedule defines how the database processes multiple transactions. It also keep the consideration that every instruction is performed correctly while maintaining data consistency.
Example − Consider there are two transactions, T1 and T2. They are working on shared data items A and B −
- T1 − Reads and writes A, then reads and writes B.
- T2 − Works on B first, then A.
The way these instructions are ordered forms a schedule.
Basic Rules of Scheduling
To keep the database consistent, scheduling must follow a set of rules as given in the following −
- All Instructions Must Be Included − Every instruction from every transaction must be part of the schedule. We cannot ignore them. Skipping instructions could cause data loss or corruption.
- Maintain Transaction Order − The order of operations within each transaction must remain unchanged. For example, if T1 reads A before writing it, then the order cannot be swapped.
- Context Switching Allowed − We can switch back and forth between transactions. But this is only done when the instructions of each transaction follow the correct sequence.
Types of Schedules
Schedules fall into two main types −
- Serial Schedules
- Non-Serial Schedules
Let us look at these in detail with examples.
Serial Schedules
A serial schedule means the transactions runs one after another. They re not overlapping their operations. This method is the safest because transactions do not interfere with each other.
Example: Serial Schedule of T1 and T2
Let us arrange transactions T1 and T2 into two possible serial schedules.
| Schedule 1: T1 | Operation | Schedule 2: T2 | Operation |
|---|---|---|---|
| T2: Read(B) | Read B | ||
| T2: Write(B) | Write B | ||
| T2: Read(A) | Read A | ||
| T2: Write(A) | Write A | ||
| T1: Read(A) | Read A | ||
| T1: Write(A) | Write A | ||
| T1: Read(B) | Read B | ||
| T1: Write(B) | Write B |
In this schedule, T2 runs fully before T1 starts. Since only one transaction runs at a time, there is no risk of data inconsistency.
- Advantage − No risk of conflicts or data errors.
- Disadvantage − No concurrency. Only one transaction runs at a time, slowing down the system.
Non-Serial Schedules
Non-serial schedules allow overlapping transactions, enabling concurrency but increasing the chance of conflicts.
Example: Non-Serial Schedule of T1 and T2
Here is an example where instructions from T1 and T2 are interleaved −
| Schedule 1: T1 | Operation | Schedule 2: T2 | Operation |
|---|---|---|---|
| T1: Read(A) | Read A | ||
| T1: Write(A) | Write A | ||
| T2: Read(B) | Read B | ||
| T2: Write(B) | Write B | ||
| T1: Read(B) | Read B | ||
| T1: Write(B) | Write B | ||
| T2: Read(A) | Read A | ||
| T2: Write(A) | Write A |
In this schedule, instructions from T1 and T2 are mixed. This is allowing both transactions to run concurrently. However, incorrect interleaving could lead to data inconsistencies if done carelessly.
Key Insight
- Advantage − Allows for concurrency, improving system performance.
- Disadvantage − Increases the risk of data conflicts due to overlapping operations.
Importance of Non-Serial Schedules
Non-serial schedules are used because they −
- Boost Resource Efficiency − More transactions can run simultaneously. This is reducing idle time.
- Lower Waiting Time − Transactions spend less time waiting for execution.
However, these benefits come at a cost. If the scheduling is not done correctly then the database could become inconsistent. That is where conflict serializability helps to get even non-serial schedules maintain data accuracy.
Calculating Possible Schedules
How many different serial schedules can exist for n transactions. To find that we can use formula as n! (n factorial) because each transaction can occupy any position in the schedule.
Example − Suppose there are three transactions T1, T2, and T3. The number of possible serial schedules would be −
$3! = 3 \times 2 \times 1 = 6$
The possible schedules would be −
- T1 → T2 → T3
- T1 → T3 → T2
- T2 → T1 → T3
- T2 → T3 → T1
- T3 → T1 → T2
- T3 → T2 → T1
For non-serial schedules, the number depends on the total instructions. Also depends on how they are interleaved while respecting each transactionâs internal order.
Advanced Calculation for Non-Serial Schedules
If transactions contain different numbers of instructions, the calculation becomes more complex. Suppose T1 has $n_1$ instructions, T2 has $n_2$, and Tn has $n_n$. The total instructions would be −
Total Instructions = $n_1 + n_2 + ... + n_n$
To calculate possible non-serial schedules while keeping individual transaction orders intact, use the formula −
Total Schedules = $\frac{(n_1 + n_2 + \cdots + n_n )!}{(n_1 ! \times n_2 ! \times \cdots \times n_n !)}$
Conclusion
In this chapter, we explained in detail the concept of scheduling in transactions. We discussed what a schedule is and why it is essential for database management. We also explored two primary types of schedules: serial and non-serial schedules. Serial schedules guarantee data consistency but do not support concurrency, which makes them slow in real-world scenarios. Non-serial schedules, while offering better performance, come with the risk of data conflicts.
We also learned how to calculate the number of possible schedules and why conflict serializability is useful in handling non-serial schedules.