Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL multiple transactions incrementing same row

I need help with understanding resultant behaviour of concurrent transactions updating same row of the database.

Database : MySQL

Scenario:

1) Transaction A will update row (1,2,3)
2) Transaction B will update row (1,3,4)

Since both transactions are executing in parallel, in auto-commit mode turned off, would the final state (for row 1 and 3) will reflect the changes made by both A and B or there is a potential for data loss.

Also would the answer change if the transactions are simply incrementing the data records?

like image 349
user1855193 Avatar asked Aug 11 '26 04:08

user1855193


1 Answers

If both transactions update the same row, the second transaction will be blocked until the first transaction is either rolled back or committed. In other words the transactions will not run in parallel at the end.

This actually depends on isolation level, see for example http://developer.mimer.com/documentation/latest_jdbcguide_html/programming.html for details.

like image 73
Zbynek Vyskovsky - kvr000 Avatar answered Aug 12 '26 16:08

Zbynek Vyskovsky - kvr000



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!