Next-Key Locking
A locking mechanism that locks a row plus the gap before the next row to prevent phantom reads.
In a relational database, two transactions can hit a phantom-read problem: the first reads all rows where "status = new" and finds 5. The second inserts a new row with "status = new." The first re-reads the same query and finds 6 — something appeared from nowhere. Next-key locking solves this by locking not just the matching rows but also the gap between rows — the slot where someone could insert something. If a transaction locks rows where id = 100, 105, it also locks the gap between 105 and the next id (say 110), preventing inserts there. It's an advanced scheme requiring sorted indexes. MySQL InnoDB uses it for its highest isolation level.