[thelist] MySQL queries and AUTO_INCREMENT

sbeam sbeam at onsetcorps.net
Fri Apr 7 15:18:28 CDT 2006


On Friday 07 April 2006 02:20 pm, Matt Warden wrote:
> > $res = $db->query("SELECT id, file_name FROM photos");
> > $pic = $res->fetchRow(DB_FETCHMODE_ASSOC, rand(1, $res->numRows());
> > $res->free();
> >
> rand() is not very expensive. Psuedo-random number generation is a
> simple calculation based on the previous (or seed) value. It's a good
> thought to avoid the many calculations, but transferring data over a
> network is expensive, so returning all the rows in the table would
> most certainly be slower.

OK, rand() is not expensive, granted. But ORDER BY can be (somewhat). 
And I'd assume the client and the DB are on the same machine here. 
Besides I've always understood that RDBMSs don't send any parts of the 
result set over the wire (or even read them off disk, unless a temp 
table or cursor is created?) until you actually fetch the row. So in 
this case the only bits that are moved are the ones corresponding to 
the single row at the pointer position.

-- 

# S Beam - Web App Dev Servs
# http://www.onsetcorps.net/



More information about the thelist mailing list