Table of Contents#
- Fundamentals of Database Transactions
- ACID Properties
- Transaction States
- Schedules & Serializability
- Concurrency Control Techniques
- Locking Protocols
- Timestamp Ordering
- Multiversion Concurrency Control (MVCC)
- Optimistic Concurrency Control
- GATE PYQ Analysis (2010–2025)
- Topic-wise PYQs
- Solved Examples
- Best Practices for GATE Preparation
- Common Pitfalls & How to Avoid Them
- Conclusion
- References
1. Fundamentals of Database Transactions#
A transaction is a logical unit of work (e.g., transferring money, updating a record) that must execute atomically, consistently, isolatedly, and durably (ACID properties).
1.1 ACID Properties#
- Atomicity: A transaction executes entirely or not at all.
Example: Transferring $100 from Account A to B. Either both accounts are updated, or neither. - Consistency: A transaction transforms the database from one consistent state to another.
Example: Total bank balance (A + B) remains unchanged after the transfer. - Isolation: Concurrent transactions do not interfere with each other.
Example: While T1 transfers money, T2 (checking balance) sees a consistent state. - Durability: Once committed, a transaction’s changes are permanent (survive system failures).
1.2 Transaction States#
A transaction moves through states:
- Active: Executing operations.
- Partially Committed: All operations complete, but changes are not yet durable.
- Committed: Changes are durable (permanent).
- Aborted: Transaction fails; changes are rolled back.
State Transition:
Active → (execute operations) → Partially Committed → (commit) → Committed
Active → (abort) → Aborted → (rollback) → Active (restart)
1.3 Schedules & Serializability#
A schedule is a sequence of operations from multiple transactions.
- Serial Schedule: Transactions execute one after another (e.g., T1 → T2 → T3).
- Serializable Schedule: Equivalent to a serial schedule (preserves database consistency).
- Conflict Serializable: A schedule is conflict serializable if its conflict graph (nodes = transactions, edges = conflicting operations) has no cycles.
Example:
Schedule S: T1: R(A), T2: R(A), T1: W(A), T2: W(A)
- Conflicting operations:
T1:W(A)andT2:W(A)(same data, write-write),T1:R(A)andT2:W(A)(read-write),T2:R(A)andT1:W(A)(read-write). - Conflict graph: Edges
T1→T2(fromT1:W(A)→T2:W(A)) andT1→T2(fromT1:R(A)→T2:W(A)), andT2→T1(fromT2:R(A)→T1:W(A)). - The graph has a cycle (T1→T2→T1), so S is NOT conflict serializable.
2. Concurrency Control Techniques#
Concurrency control ensures multiple transactions execute without conflicting (e.g., lost updates, dirty reads).
2.1 Locking Protocols#
Locks (Shared S, Exclusive X) prevent conflicting operations:
- Shared (S) Lock: Multiple transactions can read (but not write) the data.
- Exclusive (X) Lock: Only one transaction can write (or read-write) the data.
Two-Phase Locking (2PL)#
- Growing Phase: Acquire locks (no releases).
- Shrinking Phase: Release locks (no acquires).
Example:
- T1 (growing):
X-Lock(A),Read(A),Write(A) - T1 (shrinking):
Unlock(A)
Strict 2PL#
Holds exclusive locks until the transaction commits (avoids dirty reads).
2.2 Timestamp Ordering#
Each transaction gets a unique timestamp (e.g., start time). Operations are ordered by timestamp:
- Thomas’ Write Rule: Ignore obsolete writes (e.g., a transaction with an older timestamp writing to data already updated by a newer transaction).
Example:
- T1 (ts=100) reads
A. - T2 (ts=200) writes
A(allowed, as T2 is newer). - If T1 (ts=100) writes
Aafter T2 (ts=200) readsA, T1’s write is obsolete (ignored).
2.3 Multiversion Concurrency Control (MVCC)#
Maintain multiple versions of data. Readers access older versions, so writers do not block readers.
Example:
- T1 writes
A(version 1). - T2 reads
A(version 1) while T3 writesA(version 2).
2.4 Optimistic Concurrency Control#
Assume no conflicts during execution. Check for conflicts at commit:
- Phases: Read (execute operations), Validation (check conflicts), Write (apply changes if valid).
3. GATE PYQ Analysis (2010–2025)#
GATE PYQs test concepts like ACID, serializability, locking, and timestamping. Below are key examples:
3.1 ACID Property Questions#
2015 GATE: Which ACID property ensures transaction changes are persistent?
- Answer: Durability (changes survive system failures).
3.2 Schedule & Serializability Questions#
2018 GATE: Check conflict serializability of the schedule:
T1: R(X), T2: R(Y), T1: W(Y), T2: W(X)
Step-by-Step Solution:#
-
Identify Conflicting Operations:
T1:R(X)andT2:W(X)(read-write on X, T1 before T2) → EdgeT1→T2.T2:R(Y)andT1:W(Y)(read-write on Y, T2 before T1) → EdgeT2→T1.
-
Conflict Graph:
Nodes: T1, T2. Edges:T1→T2andT2→T1. -
Conclusion: Cycle exists (T1→T2→T1) → Schedule is NOT conflict serializable.
3.3 Locking & Deadlock Questions#
2020 GATE: Which locking protocol guarantees serializability?
- Answer: Two-Phase Locking (2PL) (strict 2PL is a subset).
4. Best Practices for GATE Preparation#
- Master ACID & Serializability: Revise definitions, conflict graphs, and 2PL.
- Practice PYQs: Solve 2010–2025 questions to identify patterns (e.g., serializability, lock modes).
- Draw Diagrams: For conflict graphs, transaction states, and lock timelines.
- Understand Edge Cases: E.g., Thomas’ rule in timestamping, MVCC versioning.
5. Common Pitfalls & How to Avoid Them#
- Mixing Conflict and View Serializability: Focus on conflict serializability (GATE emphasizes this).
- Forgetting 2PL Phases: Remember: Growing (acquire, no release), Shrinking (release, no acquire).
- Misapplying Thomas’ Rule: Check timestamps—obsolete writes (older timestamp) are ignored.
6. Conclusion#
Transactions and Concurrency Control are foundational for DBMS and GATE. Master ACID, serializability, and locking protocols, and practice PYQs to excel. Consistency in practice (pun intended!) is key.
7. References#
- Database System Concepts (Korth, Sudarshan, Navathe)
- GATE Previous Year Question Papers (2010–2025)
- Online Resources: NPTEL DBMS Lectures, GATE Overflow
This blog equips you to tackle GATE questions on Transactions & Concurrency Control. For deeper practice, explore PYQs and experiment with example schedules!