I have an application in which a user performs an action and receives points. Would it be better to try to perform arithmetic in the application and update the field of the points database with the obtained value or create a mathematics database?
Assuming a user with 0 points should get 2 extra:
//app does the math (0+2) and issues this statement
update users set points = 2 where id = 1
vs
//app only knows to update by 2, db does the math
update users set points = points+2 where id = 1
Is there any difference in SQL performance? Is one approach better than another in terms of application design, where should this logic be, etc.?
Edit: This edit may come too late to serve a lot of good, but I just wanted to answer some reviews and make clarifications. Although I'm curious about any difference in db performance, this is not a problem. My concern is where this logic will live best and why it should be preferred over another and in what scenarios.
On the one hand, almost all of my logic is inside the application, so it would be advisable to do the math there as Hank’s answer . But, on the other hand, there are some potential latency / thread issues that may suggest that the logic should be executed by db, as shown by Blixt and Andrew .