Sample questions
Question 1Easy
A simple way some DBMSs handle deadlocks without building a graph is:
- Ignoring writes
- Making every lock shared
- Disabling transactions
- Lock timeouts: abort a transaction that waits too long
Answer: D. Lock timeouts: abort a transaction that waits too long
Explanation
Timeouts are cheap but may abort transactions that were merely slow, not deadlocked.
Step-by-step solution
- Deadlock detection usually builds a wait-for graph and looks for cycles.
- A simpler method sets a maximum wait time for each lock request.
- If a transaction waits longer, it is assumed deadlocked and aborted.
Why the other options are wrong
- A. Ignoring writes would break correctness.
- B. Writes need exclusive locks, so all-shared locking is impossible.
- C. Without transactions there is no atomicity.
Tip: Timeout is simple but can give false positives; a wait-for graph is exact but costs more.
Question 2Easy
Which lock must a transaction hold before it can update a data item under lock-based protocols?
- Exclusive (X) lock
- Intention-shared (IS) lock
- Shared (S) lock
- No lock is needed
Answer: A. Exclusive (X) lock
Explanation
Writing requires an exclusive lock so that no other transaction reads or writes the item at the same time.
Step-by-step solution
- Updating an item is a write.
- Writes need an exclusive (X) lock.
- X ensures no other transaction reads or writes the item at the same time.
Why the other options are wrong
- B. IS is placed on ancestors to signal reads below.
- C. S allows reading only.
- D. Lock-based protocols require a lock for every access.
Tip: Read needs S; write needs X.
Question 3Easy
Starvation in concurrency control means:
- The log runs out of space
- A transaction reads uncommitted data
- A transaction waits indefinitely while others keep getting the lock
- All transactions are deadlocked in a single cycle and none of them can proceed
Answer: C. A transaction waits indefinitely while others keep getting the lock
Explanation
A fair (FIFO) lock queue or aging prevents a transaction from being passed over forever.
Step-by-step solution
- A transaction keeps asking for a lock.
- Other transactions keep being granted it first.
- It waits indefinitely even though the system as a whole makes progress: that is starvation.
Why the other options are wrong
- A. A full log is a storage problem.
- B. Reading uncommitted data is a dirty read.
- D. That describes deadlock; in starvation others still proceed.
Tip: Deadlock: everyone stuck. Starvation: one is stuck while others move.
Question 4Easy
Which SQL isolation level is the weakest and permits dirty reads?
- READ COMMITTED
- SERIALIZABLE
- REPEATABLE READ
- READ UNCOMMITTED
Answer: D. READ UNCOMMITTED
Explanation
READ UNCOMMITTED allows reading other transactions' uncommitted changes. The other levels progressively prevent more anomalies.
Step-by-step solution
- The four standard levels from weakest to strongest are READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ and SERIALIZABLE.
- Only READ UNCOMMITTED allows dirty reads.
- So it is the weakest.
Why the other options are wrong
- A. READ COMMITTED blocks dirty reads.
- B. SERIALIZABLE is the strongest.
- C. REPEATABLE READ blocks dirty and non-repeatable reads.
Tip: UC -> C -> RR -> S: each level blocks one more anomaly.
Question 5Medium
T1 reads a row, T2 updates and commits that row, and T1 reads it again getting a different value. This anomaly is a:
- Lost update
- Phantom read
- Dirty read
- Non-repeatable read
Answer: D. Non-repeatable read
Explanation
A dirty read reads uncommitted data. A phantom is a new row appearing in a repeated range query. A non-repeatable read sees a changed value of the same row.
Step-by-step solution
- T1 reads the row, then T2 updates it and commits.
- T1 reads the same row again and sees a new value.
- Re-reading a row and getting a different value is a non-repeatable read.
Why the other options are wrong
- A. A lost update is one write overwriting another.
- B. A phantom read is new rows matching a query, not a changed row.
- C. T2 committed, so the value T1 read was not dirty.
Tip: Same row, new value = non-repeatable; new rows = phantom.
Question 6Medium
Is the following schedule conflict serializable?
R1(A) W2(A) R2(B) W1(B)
- No, because two transactions cannot both access item B within one schedule
- No, because the precedence graph has a cycle T1 -> T2 -> T1
- Yes, equivalent to T2 then T1
- Yes, equivalent to T1 then T2
Answer: B. No, because the precedence graph has a cycle T1 -> T2 -> T1
Explanation
R1(A) before W2(A) gives edge T1 -> T2. R2(B) before W1(B) gives edge T2 -> T1. The cycle means no equivalent serial order exists.
Step-by-step solution
- R1(A) before W2(A): edge T1 -> T2.
- R2(B) before W1(B): edge T2 -> T1.
- The graph has a cycle, so the schedule is not conflict serializable.
Why the other options are wrong
- A. Many transactions can access the same item in a schedule.
- C. T2 then T1 would put W2(A) before R1(A), changing what T1 reads.
- D. T1 then T2 would put W1(B) before R2(B), changing what T2 reads.
Tip: Cycle in the precedence graph = not conflict serializable.
Question 7Medium
T1 holds an intention-exclusive (IX) lock on a table. Which lock can T2 also get on the same table?
- SIX
- X
- S
- IS or IX
Answer: D. IS or IX
Explanation
IX is compatible with IS and IX, since the actual conflicts are checked at the row level; it conflicts with S, SIX and X on the table.
Step-by-step solution
- IX means T1 intends to lock some rows exclusively.
- IS and IX are compatible with IX, since rows are checked at the finer level.
- S, SIX and X on the whole table conflict with IX.
Why the other options are wrong
- A. SIX includes a table-level S, which conflicts with IX.
- B. X on the whole table conflicts with everything.
- C. S on the whole table would read rows T1 may be changing.
Tip: IX is compatible only with IS and IX.
Question 8Medium
In multiversion concurrency control (MVCC), why do readers not block writers?
- Writers are made to wait until every active reader of the item has finished
- Readers take exclusive locks first
- Readers see an older committed version while writers create new versions
- Readers always read uncommitted data
Answer: C. Readers see an older committed version while writers create new versions
Explanation
Each write creates a new version, so a reader can use the version valid for its snapshot without locking out the writer.
Step-by-step solution
- A writer creates a new version of the row.
- Readers keep reading the last committed version from their snapshot.
- They need no shared locks, so they do not block writers.
Why the other options are wrong
- A. In MVCC, writers do not wait for readers.
- B. Readers do not take exclusive locks.
- D. Readers see committed data, not dirty data.
Tip: MVCC: readers don't block writers, writers don't block readers.
Question 9Hard
Why do wait-die and wound-wait restart an aborted transaction with its ORIGINAL timestamp?
- Because new timestamps cannot be generated during recovery
- So it eventually becomes the oldest and cannot starve
- To keep the precedence graph acyclic
- So that its writes become visible earlier
Answer: B. So it eventually becomes the oldest and cannot starve
Explanation
Keeping the old timestamp means the transaction gets relatively older over time, so it eventually gets priority.
Step-by-step solution
- Both schemes favour older transactions.
- A restarted transaction keeps its original timestamp.
- As others finish, it becomes the oldest, so it can no longer be rolled back: no starvation.
Why the other options are wrong
- A. New timestamps can always be generated.
- C. These schemes prevent deadlock; they do not manage precedence graphs.
- D. Timestamps do not affect when writes become visible.
Tip: Keep the old timestamp = eventually the oldest = no starvation.
Question 10Hard
A waits-for graph contains T1 -> T2, T2 -> T3, T3 -> T4 and T4 -> T2. Which transactions are deadlocked?
- T1, T2, T3 and T4
- T2, T3 and T4
- None, since T1 is not in the cycle
- T1 and T2 only
Answer: B. T2, T3 and T4
Explanation
The cycle is T2 -> T3 -> T4 -> T2. T1 is waiting on a deadlocked transaction but is not part of the cycle; aborting a cycle member frees it.
Step-by-step solution
- The cycle is T2 -> T3 -> T4 -> T2.
- Those three are deadlocked.
- T1 waits for T2 but is not in the cycle; it is blocked, and will continue once the deadlock is broken.
Why the other options are wrong
- A. T1 is waiting but is not part of the cycle.
- C. A cycle exists among T2, T3 and T4.
- D. T1 and T2 do not form a cycle.
Tip: Deadlocked = on the cycle.
Practise all 35 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →