make InnoDB only lock the row currently being UPDATEd?

有些话、适合烂在心里 提交于 2019-12-12 03:38:37

问题


Building on the query in this answer (please note/assume that the GROUP_CONCATs are now also held in user defined variables), when and what will InnoDB lock on table1?

I'd prefer that it only lock the table1 row that it's currently updating and release it upon starting on the next row.

I'd also prefer that when it locks table2 (or its' rows) that SELECTs will at least be able to read it.

The column being updated is not PK or even indexed.

How can this be achieved, or is it already doing that?

This is in a TRIGGER.

Many thanks in advance!


回答1:


The lock is held for the entire transaction (as the operation is atomic, this means that either all of the rows are updated or no rows) and you can't change that (without changing the storage engine). However it does not block reads (unless you are in SEIALIZABLE isolation level), so SELECT queries will be executed, but they will read the old values. Only SELECT FOR UPDATE and SELECT...LOCK IN SHARE MODE will be blocked by an update.



来源:https://stackoverflow.com/questions/14221983/make-innodb-only-lock-the-row-currently-being-updated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!