> How many rows do you anticipate that the table will have? Have you
> tested this on your server? I would have to bet that if you
> have only a few K rows that speed/performance will not be an issue.
I doubt I will have more than 100. Perhaps I shouldn't worry about it,
then.
> The way to
> enhance this is by selecting an indexed value, such as the following
> where `foo` is indexed
>
> SELECT `foo` FROM fortunes ORDER BY RAND() LIMIT 1
Why does this help? From the MySQL book I have, the reason ORDER BY
RAND() is slow is because "for each record in the table a random number
must be generated. Then all random numbers are sorted so that the first
n records can be returned.
Is this correct? If so, how does selecting an indexed column help this,
won't it still need to perform all those operations (generate rand-nums,
then sort) regardless of the index?
Jfyi the book I am referring to is "MySQL" by Michael Kofler. I'd give
the Amazon link but they appear to be down at the moment. The ISBN is
1-893115-57-7 for any who want to look it up elsewhere/when amazon.com
comes back up.
-jb