Timestamp-based protocols in DBMS Theory - Time & Space Complexity
We want to understand how the time needed for timestamp-based protocols changes as the number of transactions grows.
Specifically, how does the system handle more transactions and what costs increase?
Analyze the time complexity of the following timestamp-based concurrency control steps.
// For each transaction T with timestamp TS(T):
// For each data item X accessed by T:
// If TS(T) < read_TS(X), abort T
// Else if TS(T) < write_TS(X), abort T
// Else allow read or write and update TS(X)
This code checks timestamps to decide if a transaction can read or write a data item safely.
Look at what repeats as input grows.
- Primary operation: Checking timestamps for each data item accessed by each transaction.
- How many times: For each transaction, the protocol checks every data item it uses.
As the number of transactions and data items accessed grows, the checks increase proportionally.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 transactions | About 10 x data items per transaction checks |
| 100 transactions | About 100 x data items per transaction checks |
| 1000 transactions | About 1000 x data items per transaction checks |
Pattern observation: The total checks grow roughly in direct proportion to the number of transactions and their data accesses.
Time Complexity: O(n * m)
This means the time to process transactions grows linearly with the number of transactions and the number of data items accessed per transaction.
[X] Wrong: "Timestamp checks happen only once per transaction regardless of data items."
[OK] Correct: Each data item accessed requires a timestamp check, so the total work depends on all data accesses, not just the number of transactions.
Understanding how timestamp-based protocols scale helps you explain concurrency control in databases clearly and confidently.
What if we changed the protocol to check timestamps only at the start and end of transactions? How would the time complexity change?
Practice
Solution
Step 1: Understand the role of timestamps
Timestamps assign a unique number to each transaction to order them.Step 2: Identify the main purpose in protocols
This ordering helps the system decide which transaction can read or write data safely.Final Answer:
To give each transaction a unique order number -> Option AQuick Check:
Timestamps = Unique order number [OK]
- Confusing timestamps with encryption keys
- Thinking timestamps store data permanently
- Assuming timestamps handle backups
Solution
Step 1: Understand timestamp assignment
Timestamps are usually assigned based on the current system time to reflect order.Step 2: Evaluate options
Random numbers or transaction IDs do not guarantee correct ordering; timestamps must be assigned before commit.Final Answer:
Assign the current system time as the timestamp -> Option AQuick Check:
Timestamp = Current system time [OK]
- Using random numbers instead of time
- Assigning timestamp after commit
- Confusing transaction ID with timestamp
Solution
Step 1: Compare timestamps of T1 and T2
T1 has timestamp 5 (older), T2 has timestamp 10 (newer).Step 2: Apply timestamp protocol rule
Older transactions cannot overwrite changes made by newer transactions, so T1 must be rolled back.Final Answer:
T1 will be rolled back to prevent overwriting newer data -> Option CQuick Check:
Older transaction rollback = T1 rollback [OK]
- Thinking older transactions can overwrite newer writes
- Assuming both transactions commit
- Confusing which transaction rolls back
Solution
Step 1: Compare timestamps of T3 and T4
T3 has timestamp 15 (older), T4 has timestamp 20 (newer).Step 2: Apply read rule in timestamp protocol
Older transactions cannot read data written by newer transactions because it causes inconsistency.Final Answer:
T3 should not read because it is older than T4's write -> Option DQuick Check:
Older transaction reading newer write = Not allowed [OK]
- Assuming older transactions can read newer writes
- Thinking newer transaction rolls back
- Believing reading old value is always allowed
Solution
Step 1: Analyze timestamps of T5 and T6
T5 has timestamp 25 (older), T6 has timestamp 30 (newer).Step 2: Apply write rule in timestamp protocol
Older transaction T5 cannot write if a newer transaction T6 has already read the data, to avoid inconsistency.Step 3: Decide action to maintain consistency
T5 must be rolled back to prevent overwriting data read by newer transaction T6.Final Answer:
T5 should be rolled back because it is older than T6 -> Option BQuick Check:
Older write after newer read = Rollback older [OK]
- Allowing older writes after newer reads
- Rolling back newer transaction incorrectly
- Assuming both can proceed safely
Ready to prove it?
Pass the test and this pattern moves unknown
