我试图防止代码中出现死锁,因为我可能会在项目的不同部分使用两者。
它们是否以相同的顺序锁定行?
嵌套
select * from `carts` where `carts`.`user_id` = ? and exists ( select * from `cart_items` where `carts`.`id` = `cart_items`.`cart_id` for update ) for update
分离
select * from `carts` where `carts`.`user_id` = ? for update
select * from `cart_items` where `cart_id` = ? for update