ACID properties in DBMS Theory - Time & Space Complexity
We want to understand how the time to complete database transactions changes as the amount of data or operations grows.
Specifically, how the ACID properties affect the time it takes to process transactions.
Analyze the time complexity of a transaction ensuring ACID properties.
BEGIN TRANSACTION;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;
This code transfers money between two accounts within a transaction that must be atomic, consistent, isolated, and durable.
Look for operations that repeat or scale with input size.
- Primary operation: The updates on account balances inside the transaction.
- How many times: Each update runs once per account involved, but the transaction may include many such operations if more accounts are involved.
As the number of operations in a transaction grows, the time to ensure ACID properties grows too.
| Input Size (number of operations) | Approx. Operations |
|---|---|
| 2 | Few operations to update and log changes |
| 10 | More updates and checks, time grows roughly linearly |
| 100 | Many updates, more locking and logging, time grows proportionally |
Pattern observation: The time grows roughly in proportion to the number of operations in the transaction.
Time Complexity: O(n)
This means the time to complete a transaction grows linearly with the number of operations it contains.
[X] Wrong: "ACID properties make transaction time constant regardless of size."
[OK] Correct: Ensuring atomicity, consistency, isolation, and durability requires work for each operation, so time grows with transaction size.
Understanding how transaction time grows helps you design efficient database operations and explain trade-offs clearly in interviews.
"What if the transaction included nested transactions? How would the time complexity change?"