问题
Building on the query in this answer (please note/assume that the GROUP_CONCAT
s 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 SELECT
s 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