更新锁:for update
// 进程1
begin;
select * from t where id = 1 for update;
现在开启另一个进程
// 进程2
select * from t where id = 1 for update; // 此查询会等待进程1提交,或进程关闭后才执行。
select * from t where id = 1; // 此查询不会等待,直接执行。
再开启一个进程
// 进程3
begin;
select * from t where id = 1 for update; // 此查询会等待进程1提交,或进程关闭后才执行。
select * from t where id = 1; // 此查询不会等待,直接执行。
事务不能嵌套
DB::transaction()
嵌套。框架中实际只会执行一次事务。