Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
-- Gap lock example -- Table: orders with id 1, 5, 10 START TRANSACTION; SELECT * FROM orders WHERE id BETWEEN 3 AND 7 FOR UPDATE; -- Locks the gap between 1 and 5, rows 5, and gap between 5 and 10 -- Another session cannot INSERT id=4 or id=6 until first commits -- To reduce gap locking: use READ COMMITTED isolation level SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
Result
Open