create table foo(foo_id int auto_increment primary key, bar_id int); create unique index bar_id_idx on foo (bar_id); set autocommit=0; start transaction; insert into foo (bar_id) values (1); delete from foo where foo_id = 1; insert into foo (bar_id) values (1); select sleep(20); commit; set autocommit=1;