How would you prevent overlapping reservations under concurrent requests in InnoDB?
A reservation service runs on MySQL 8.4 with InnoDB at the REPEATABLE READ isolation level. Before creating a reservation, a transaction checks whether the requested time interval overlaps an existing reservation for the same resource. A developer proposes using SELECT ... FOR UPDATE and inserting the reservation if no matching rows are found. Two clients try to reserve the same available interval simultaneously. What locks will InnoDB acquire? How do the indexes and query conditions affect its behavior? Propose a method that reliably prevents overlapping reservations.
ExplainTransactions and locksSeniorBackendData Engineer