Reputation: 75
which version is better (performance)?
1. update my_table set my_col = 1 where my_id = 100
update my_table set my_col = 1 where my_id = 110
update my_table set my_col = 1 where my_id = 120
2. update my_table set my_col = 1 where my_id in (100, 110, 120)
Upvotes: 1
Views: 284
Reputation: 8571
In your case, both ways will have almost equal response time as you are running only 3-4 queries.
But definitely 2nd way will be faster for higher number of queries or updates (bulk updates are faster) because this will reduce,
but bulk updates has one downside also i.e. locking of tables as you are updating multiple records in single statement, table will be locked for that much duration. so perform bulk updates with considering acceptable locking period in mind.
Upvotes: 1