I'm seeing queries a little bit slower than I'd like when I try to get
them in random order, by using ORDER BY RAND().  It seems like mysql
should be able to do this quickly, especially in the simple case of:

    SELECT * FROM db ORDER BY RAND() LIMIT 1

, where it could choose a random number between the first and last row
and display that row.

Is there any way to speed this up?

For the common case above, I've been looking at assigning each row a
number, then just counting rows, picking a number between one and the
number of rows, and selecting that records by number; that seemed to
be about 25 times faster in quick benchmarks.  Unfortunately, it
doesn't work well if I need to use any WHERE clauses in my select,
since I don't know what random numbers to pick.

Has anybody done something like this before who would like to share
some tips?

Thanks!

----ScottG.

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to