励志网站织梦源码,做电子杂志用什么网站,工业品企业网站源码,镇江网站制作价格一 作用
1.1 结论
在mysql中#xff0c;select ... for update 仅适用于InnoDB#xff0c;且必须在事务块中才能生效。Innodb引擎默认是行锁。 Select .... from where .... for update 如果在where的查询条件字段使用了【主键|索引】#xff0c;则此命令上行锁。否…一 作用
1.1 结论
在mysql中select ... for update 仅适用于InnoDB且必须在事务块中才能生效。Innodb引擎默认是行锁。 Select .... from where .... for update 如果在where的查询条件字段使用了【主键|索引】则此命令上行锁。否则则命令上表锁。它是悲观锁的一种实现方式。
1.2 操作案例
1.2.1 查询条件为主键
场景1查询条件为主键
会话A select * from tb_pab where id1 for update;
会话B update tb_pab set unamebj where id1;》出现阻塞 结论select for update 查询条件为主键则进行上行锁。
1.2.2 查询条件为唯一索引
场景2查询条件为唯一索引
会话A select * from tb_pab where code001 for update;
会话B update tb_pab set unamebj123 where id1;》出现阻塞
会话C update tb_pab set unamebj123 where id2; 非阻塞 结论select for update 查询条件为索引则进行上行锁。
1.2.3 查询条件为普通字段不加索引和主键
场景3查询条件为普通字段不加索引和主键
会话A select * from tb_pab where namesh for update;
会话B update tb_pab set unamesh2 where id1;》出现阻塞
会话Cupdate tb_pab set unamesh2 where id2;》出现阻塞 结论select for update 查询条件非【主键|索引】则进行上表锁。
SELECT...FOR UPDATE_select for update-CSDN博客