Problem Statement
What are gap or key-range locks and when are they useful?
Explanation
They protect not only existing rows but also the gaps between index keys that satisfy a range predicate. This blocks phantoms by preventing inserts into the protected range while the unit runs.
They appear in engines like InnoDB at Repeatable Read with range scans. They can reduce concurrency, so scope them with selective predicates and good indexes.
Code Solution
SolutionRead Only
-- InnoDB example range SELECT * FROM orders WHERE amount BETWEEN 100 AND 200 FOR UPDATE;
Practice Sets
This question appears in the following practice sets:
