[thelist] MySQL queries and AUTO_INCREMENT

Matt Warden mwarden at gmail.com
Fri Apr 7 13:20:41 CDT 2006


sbeam,

On 4/7/06, sbeam <sbeam at onsetcorps.net> wrote:
> Just curious - as an alternative - would there be any downside to just
> using a result set pointer/cursor - something like
>
> $res = $db->query("SELECT id, file_name FROM photos");
> $pic = $res->fetchRow(DB_FETCHMODE_ASSOC, rand(1, $res->numRows());
> $res->free();
>
> (Using PHP/PEAR because thats just what I'm used to. You could do the
> same thing lots of ways)
>
> So you are only doing one rand() in the application code and not 10^4
> rand's in SQL plus a sort.

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.

--
Matt Warden
Miami University
Oxford, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.



More information about the thelist mailing list