Transaction, incrementing and MySQL UPDATE

0 like 0 dislike
6 views
Whether is in MySQL the operation of the increment in the UPDATE transaction-safe? Possible race condition when several clients simultaneously execute a query like "UPDATE mytable SET myfield=myfield+1 WHERE id=myid"? If a thousand clients at the same time will perform the query on the line with a base value of 0, whether the end value is equal to one thousand?

Talking about InnoDB.
by | 6 views

6 Answers

0 like 0 dislike
In InnoDB row locks should not be Achtung.
by
0 like 0 dislike
Yes, will be equal to exactly 1000 at the end. regardless of the engine. In different engines this is achieved in different ways. Namprimer in innodb blokirovki a specific record. In Myisam lock the whole table for a short time.
by
0 like 0 dislike
Don't see any reason to say "no". Otherwise just defeats the purpose of a relational DBMS.
by
0 like 0 dislike
The record given by you, it is absolutely safe transaction. The line is blocked, changed, rasplachivaetsya.
by
0 like 0 dislike
View principle of operation update.
The record is locked, then update is performed and then you can only work with this record. In principle, because of this, some articles on optimizing and reducing load on the server, it is recommended not to use often update
by
0 like 0 dislike
Not the fact that the value will be 1000, especially given the fact that InnoDB is used MVCC is Given by the simultaneous implementation of 1000 queries, each of them will increase the value from zero to one.
by

Related questions

0 like 0 dislike
1 answer
asked Apr 9, 2019 by vetsmen
0 like 0 dislike
3 answers
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Jun 14, 2019 by Artem0071
110,608 questions
257,186 answers
0 comments
1,134 users