Characterizing Schedules Based on Serializability
Characterizing Schedules Based on Serializability
To determine whether a schedule is correct, the concept of serializability is used.
Serializability helps identify which concurrent schedules behave the same as a serial schedule.
1. Serial Schedules
A serial schedule is a schedule where transactions execute one after another without interleaving.
Only one transaction runs at a time.
Example
Two transactions: T1 and T2
Possible serial schedules:
Serial Schedule A
Serial Schedule B
These schedules are always correct, because:
Each transaction runs in isolation
No interference occurs between transactions
This assumption is valid because every transaction is assumed to maintain database consistency when executed alone.
2. Nonserial Schedules
A nonserial schedule occurs when operations from different transactions are interleaved.
Example:
Here both transactions execute simultaneously, mixing their operations.
Nonserial schedules allow concurrency, but they may produce incorrect results.
A nonserial schedule occurs when operations from different transactions are interleaved.
Example:
Here both transactions execute simultaneously, mixing their operations.
Nonserial schedules allow concurrency, but they may produce incorrect results.
3. Why Serial Schedules Are Not Practical
Although serial schedules guarantee correctness, they have major disadvantages:
Although serial schedules guarantee correctness, they have major disadvantages:
1. Poor CPU Utilization
If a transaction waits for I/O operations, the CPU remains idle.
Example:
If a transaction waits for I/O operations, the CPU remains idle.
Example:
2. Long Waiting Time
If one transaction is very long, other transactions must wait.
Example:
This reduces system performance.
If one transaction is very long, other transactions must wait.
Example:
This reduces system performance.
Solution
Allow interleaving of transactions while ensuring correctness.
This leads to the concept of serializability.
Allow interleaving of transactions while ensuring correctness.
This leads to the concept of serializability.
4. Serializability
A schedule is serializable if:
Its result is equivalent to the result of some serial schedule.
In other words:
Even though operations are interleaved, the final result is the same as if transactions executed one after another.
Serializable schedules are considered correct schedules.
A schedule is serializable if:
Its result is equivalent to the result of some serial schedule.
In other words:
Even though operations are interleaved, the final result is the same as if transactions executed one after another.
Serializable schedules are considered correct schedules.
5. Example with Transactions
Suppose the database initially has:
Transactions:
Suppose the database initially has:
Transactions:
Transaction T1
Transaction T2
Expected Result
After both transactions:
After both transactions:
6. Serial Execution
Serial Schedule A
Result:
Correct.
Result:
Correct.
Serial Schedule B
Result:
Also correct.
Result:
Also correct.
7. Nonserial Schedules
When operations are interleaved, results may differ.
When operations are interleaved, results may differ.
Schedule C
Produces:
This result is incorrect.
The reason is the Lost Update Problem.
Produces:
This result is incorrect.
The reason is the Lost Update Problem.
Lost Update Problem
Transaction T2 reads X before T1 updates it, so T1’s update gets overwritten.
Thus:
Transaction T2 reads X before T1 updates it, so T1’s update gets overwritten.
Thus:
Schedule D
Produces:
This result is correct.
Even though operations are interleaved, the result matches a serial schedule.
Therefore:
Produces:
This result is correct.
Even though operations are interleaved, the result matches a serial schedule.
Therefore:

Comments
Post a Comment