Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> MySQL
Author Message
jimmo
Worker
Worker



Joined: Dec 08, 2005
Posts: 107

PostPosted: Wed Aug 16, 2006 9:24 am Reply with quote

Hi All!

I am in the process of implementing a combination of the standard Nuke groups and the NSN groups. When I update the Nuke points, I want to immediately make sure that the user is the correct NSN group. Rather than querying the database to check if the user in the right group, I simply do an update for that user even if there is no change.

I found a couple of other places where this type of thing is already being done. One is update_points() in mainfile.php. In this case, the update could be avoided by first checking if points=0, in which case no update is necessary.

However, it seems to me that in my case since I have to access the database anyway why not simply do an update and not a query and then update. In any case, I have to do at least the query every time I add points. However, I am saving the time for the second DB access when I actually have to make a change. Granted, the user will have to make dozens if not hundreds of changes to move from one group to another, so an update that is really necessary will not be a common occurrence.

Writing the code would be simpler (which is a happy thing) as I don't have to build in any checks. Also, I do not see any real problems at the moment with doing the update all of the time, but I am curious as to what others think about doing it.

Regards,

jimmo
 
View user's profile Send private message
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Thu Aug 17, 2006 5:44 am Reply with quote

In this specific case that you mention, the approach sounds reasonable.

Just an "aside": I do not have experience with mySQL from a DBA perspective, but one of the things I would be concerned with if this was Oracle, is if I had archive logging turned on (i.e., all edits are logged for forward recovery purposes). An update in this case, would be very wasteful and unnecessary, and I would opt for the query/check option.

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
jimmo







PostPosted: Thu Aug 17, 2006 8:27 am Reply with quote

I've been googling for an atomic way to check and update, but I haven't found anything. A SELECT selects and an UPDATE updates. Hmmmm....

What I though about was to update using a WHERE that matches the user ID and not the group ID. I know what the group should be and only do an update if the group is different. While that does not prevent the second access, it prevents the update when it is not necessary.

Since there are only a handful of groups, I though about hardcoding the values into my custom include file which is loaded anyway. But the question is whether the extra code is worth any potential speed gains.
 
montego







PostPosted: Fri Aug 18, 2006 6:34 am Reply with quote

Quote:

What I though about was to update using a WHERE that matches the user ID and not the group ID. I know what the group should be and only do an update if the group is different. While that does not prevent the second access, it prevents the update when it is not necessary.

Sounds reasonable.

Quote:

But the question is whether the extra code is worth any potential speed gains.

Depends upon what you are after. If you see no issues with extra db calls, then add them. If you are seeking out the absolute most efficient way to do it, then it begs the question.

You should be fine with either approach.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> MySQL

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©