Do I need (I will ever need) LOCK IN SHARED MODE | FOR UPDATES as part of a transaction?

I'm scared to struggle to figure out how to write code and queries best

directly to the question: do I need or will I ever need to explicitly write LOCK IN SHARED MODEor FOR UPDATEin a transaction (except READ UNCOMMITTED)?

If I have foreign keys, do I need to explicitly select rows to apply lock to these rows or define foreign keys?

+4
source share
1 answer

Short answer: absolutely yes.

: . , , InnoDb, . , . , SELECT ... FOR UPDATE:

, -, . - , . , , , - , . MySQL FOR UPDATE, , , , .

[]

:

, , - . , ​​ . , , , , . , , . , , , , .

[]

SERIALIZABLE, MySQL . , SET autocommit = 0;, , REPEATABLE READ, LOCK IN SHARE MODE ( FOR UPDATE). , , ( ), . , LOCK IN SHARED MODE, , - .

+3

Source: https://habr.com/ru/post/1546657/


All Articles