inherit
125499
0
Nov 8, 2011 4:03:57 GMT -8
moneyman18
:-
952
June 2008
moneyman18
|
Post by moneyman18 on Apr 25, 2010 6:58:18 GMT -8
Say I have a simple form to update the values in a db. Should I get the values of the row to be updated before updating the row and compare those values with the values which were posted by the form. Then if there are any values which are not the same between the selected values and form values, perform the query to update the row with the values which are different. This way I would not have any columns that do not need updating in the update query, just the ones which values are different, or if no rows need updating not performing the query at all. OR should I just perform the update query whether the values are the different or the same either way? Am I reading this correctly? Does MySQL already basically do this? The MySQL Reference Manual states: I hope that all makes sense.
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Apr 25, 2010 9:19:20 GMT -8
That's a good question. And, yes, MySQL already does that for you. To answer the performance of this, you wouldn't want to retrieve the values first, because it would take a lot longer to retrieve them than you would save by not setting them.
|
|
inherit
125499
0
Nov 8, 2011 4:03:57 GMT -8
moneyman18
:-
952
June 2008
moneyman18
|
Post by moneyman18 on Apr 25, 2010 15:57:49 GMT -8
Thank you for the quick response. That was exactly the answer I was looking for. One more question: Would it still not be worth it performance wise if the values were already selected and stored in a variable for something that was done earlier in the same page?
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Apr 25, 2010 19:09:29 GMT -8
If that's necessary, it would probably help. But storing those variables on the page for the sole purpose of not having to update them later would likely create more problems than it solves (e.g. query loopholes), and would likely decrease the page load (to download however many bytes the extra form elements take up) by more than it would save. Also, complicate things.
So, I'd just go ahead and update all of them.
|
|