Is increment faster than setting a new value?

Viewed 24

I have two sql queries in the program:

UPDATE choice
SET count = count + $1
WHERE choice_title = $2 AND vote_id = $3  RETURNING count

and

UPDATE choice
SET count = $1
WHERE choice_title = $2 AND vote_id = $3  RETURNING count

That is, the first query in my program increases count by 1 when called, and the second assigns a new value.

At first , I used 1 variant of the query with incrementing , but then I decided to replace it in one place of the program with the second variant.Then I did some tests. The load was 1000 requests , which were made 100 in parallel.

When using first variant, all 1000 votes were saved. But when using second, less than 100 were saved.Both requests were executed in a transaction with Read Committed level.

And I wonder if it turns out that incrementing is so much faster, or is it something else?

0 Answers
Related