Frank
Frank

Reputation: 569

MySQL update tabel set count = count +1 concurrent issue

I need to update a table and set the VOTE_COUNT = VOTE_COUNT + 1 on each call, say I have 10,000 concurrent access to the database and execute the same statement at the same time:

UPDATE VOTE SET VOTE_COUNT = VOTE_COUNT + 1;

Will it be any concurrent issue which makes the result not equals to 10000? (initial count = 0)

Upvotes: 1

Views: 558

Answers (1)

PowerStat
PowerStat

Reputation: 3819

Depending on the mysql/mariadb underlying storage engine you might have concurrency or performance problems.

The best would be to have an storage engine with transaction handling - so that you would not have concurrency problems.

For the case that you use a storage engine without transaction handling, than it depends on the locking (no, row or table based).

With no locking you could have concurrency problems, because two update statements could read a value at the same time, add 1 and store it back - so one (or more) update statements will get lost! Because they will all store back the same value.

When locking the table for each update, then things will get very slow for your concurrent update statements!

Upvotes: 1

Related Questions