且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL TRIGGER 上的并发更新

更新时间:2023-02-15 09:24:55

如果用户收到 X 个并发视图,则计数器 eill 会随着问题中的更新语句增加 X.

If the user receives X concurrent views, then the counter eill be incremented by X with the update statement in the question.

作为关于 innodb 锁的 mysql 手册 解释:

UPDATE ... WHERE ... 为每条记录设置一个独占 next-key 锁搜索遇到.但是,只需要一个索引记录锁for 语句使用唯一索引锁定行以搜索唯一行.

UPDATE ... WHERE ... sets an exclusive next-key lock on every record the search encounters. However, only an index record lock is required for statements that lock rows using a unique index to search for a unique row.

Mysql 排他锁手册说:

Mysql manual on exclusive locks says:

如果事务 T1 在行 r 上持有排他 (X) 锁,则请求来自某个不同的事务 T2,用于 r 上的 [独占或共享] 类型的锁不能立即授予.相反,事务 T2 必须等待事务 T1 释放其对 r 行的锁.

If a transaction T1 holds an exclusive (X) lock on row r, a request from some distinct transaction T2 for a lock of either type [exclusive or shared] on r cannot be granted immediately. Instead, transaction T2 has to wait for transaction T1 to release its lock on row r.

总结一下:在你的应用程序级别,查看器可能是并发的,但在 mysql 级别更新是使用排他锁序列化的.

To sum it up: the viewers may be concurrent at your application level, but at mysql level updates are serialised using exclusive locks.