I have a long transaction in which a row-level lock is tested and found that it is not locked, but this part is taken out separately, and can be locked in my entire long transaction, under what circumstances will my locks be affected? SelectIdfromproduct_termwhereId & quot;. $ v [& #039; P_Term_id & #039;]. & quot; forup... I have a long transaction
A row-level lock in the middle and back of the lock
The test showed that the lock was not found.
However, you can lock this part separately.
In my entire long transaction, under what circumstances will my locks be affected?
Select Id from product_term where Id = ". $ v ['p _ Term_id ']." for update
Reply content:
I have a long transaction
A row-level lock in the middle and back of the lock
The test showed that the lock was not found.
However, you can lock this part separately.
In my entire long transaction, under what circumstances will my locks be affected?
Select Id from product_term where Id = ". $ v ['p _ Term_id ']." for update
The setting will be affected.
Actually .. First ask a question about Tom... Is it Innodb? I encountered a problem with Myisam asking about transactions ..
Okay. Return to the question.
The exclusive lock locks the query range until the transaction ends.
Just like you. The record of the corresponding ID row is locked.
However, it depends on the transaction isolation mode. If you have not changed the settings, the default setting is RR. That is to say, the SELECT statement executed before the exclusive lock has the same result .. This produces the illusion of being unlocked ..
Assume that your transaction is like this.
BEGIN;SELECT id FROM product_term where id<100;UPDATE product_term SET XXX='YYY' WHERE id = 1;...SELECT id FROM product_term where id=1 FOR UPDATE;...COMMIT;
Like this, because of the default RR level, the first range search already contains id = 1, and then the row obtained by the third in the same transaction is the same as the first line. In fact, the second row has changed the data of this row. If two concurrent threads exist, the table may not appear locked ~~
We recommend that you do this at the beginning of the transaction.
I wonder if you have encountered this problem? If yes, you can carefully study the transaction isolation mode and you will find more pitfalls.