[GLLUG] mysql help

Jeremy Bowers jerf@jerf.org
Thu, 27 Jun 2002 17:15:40 -0400


Brian Hoort wrote:
> Shouldn't you be looking for the max (highest) value of the record id? 
> It is my understanding that they never re-use old numbers.
> Something like:
> SELECT * FROM $table WHERE id=max(id)
> 

Watch the threading. If this is a web app, or anything else that can be 
multithreaded, then two copies of the script may run at once, and 
corrupt each other's data when they both get the same id. (This may 
depend on how you lock your DB's during processing. You could solve this 
by locking the DB at the top, but it's easy to leave it locked. Plus you 
slow your system down pretty badly if enough people start hitting it.)

You *really* need to hold some sort of ID field, or rederive one from 
non-changing yet unique environment parameters of some kind, if you 
really want to trust the system in a multi-threaded environment. Depends 
on what you're using this for.