Recall & Review
beginner
What is a deadlock in a database?
A deadlock happens when two or more transactions wait for each other to release locks, so none can proceed. It's like two people blocking each other in a narrow hallway.
Click to reveal answer
intermediate
How does MySQL detect deadlocks?
MySQL detects deadlocks by checking for cycles in the lock wait graph. When it finds a cycle, it chooses one transaction to roll back to break the deadlock.
Click to reveal answer
beginner
Name one common method to prevent deadlocks.
One common method is to always acquire locks in the same order in all transactions. This avoids circular waiting and prevents deadlocks.
Click to reveal answer
intermediate
What is the role of InnoDB in deadlock handling in MySQL?
InnoDB storage engine automatically detects deadlocks and rolls back one transaction to resolve it, allowing others to continue.
Click to reveal answer
beginner
Why is it important to keep transactions short to prevent deadlocks?
Short transactions hold locks for less time, reducing the chance that other transactions will wait and cause deadlocks.
Click to reveal answer
What causes a deadlock in a database?
✗ Incorrect
Deadlocks happen when transactions wait for each other’s locks, causing a cycle that stops progress.
How does MySQL resolve a detected deadlock?
✗ Incorrect
MySQL chooses one transaction to roll back, freeing locks and resolving the deadlock.
Which practice helps prevent deadlocks?
✗ Incorrect
Consistent lock order avoids circular waiting, preventing deadlocks.
What does InnoDB do when it detects a deadlock?
✗ Incorrect
InnoDB automatically rolls back one transaction to resolve deadlocks.
Why should transactions be kept short to avoid deadlocks?
✗ Incorrect
Short transactions reduce lock holding time, lowering deadlock chances.
Explain what a deadlock is and how MySQL detects and resolves it.
Think about transactions waiting for each other and how MySQL breaks the cycle.
You got /3 concepts.
Describe two ways to prevent deadlocks in database transactions.
Consider how to avoid circular waiting and reduce lock time.
You got /3 concepts.