Настройка таблицы проста < /p>
Код: Выделить всё
create table example.parent_tbl(
id int auto_increment primary key
);
create table example.child_tbl(
id int auto_increment primary key,
parent_id int not null,
update_dt timestamp default current_timestamp ON UPDATE current_timestamp,
foreign key (parent_id) references parent_tbl(id),
unique (parent_id)
);
< /code>
select
p.*
from example.parent_tbl p
where p.id not in (select parent_id from example.child_tbl)
limit 1
for update
skip locked;
столбец идентификатора в child_tbl является уникальным. У меня есть несколько процессов, работающих параллельно, и иногда один из них будет нажимать на исключение целостности, поскольку один и тот же идентификатор существует в Child_tbl . committed), current transaction should have skipped it because the row in parent_tbl is locked by the same SQL.
if it is not locked by any transaction, the ID should have appeared in child_tbl and the not in clause will filtered it out
The general query log shows the counterintuitive behaviour of this Механизм блокировки < /p>
log на стороне сервера < /p>
Существует два процесса, работающие параллельно, делая то же самое. В этом случае они являются потоком 60 и 61 соответственно. < /p>
наблюдаются два результата. Поток 60 запускает запрос, но он не сможет обнаружить строку с помощью ID 113, вставленного потоком 61. parent_tbl < /strong>. < /p>
< /li>
< /ol>
Дополнительный < /h1>
Я прохожу те же тесты с Postgresql, и я также нажима>
Подробнее здесь: https://stackoverflow.com/questions/795 ... -scenarios
Мобильная версия