5 ms·
Point 6 is a really cool way picking a random row and has never occurred to me. It does make me think though why has something like this never been optimised ou
by edd 17y ago
Point 6 is a really cool way picking a random row and has never occurred to me. It does make me think though why has something like this never been optimised out by MySQL before running the query. After all it is such a common requirement.
- bad_user 17y agoIt doesn't seem to me as a common requirement. "ORDER BY RAND()" means exactly as it says ... fetch the result-set in a random order, and it applies to the whole result-set, (probably) having the same performance characteristics as any other unoptimized "ORDER BY", which is executed before "LIMIT" (I like it because it's consistent). Many people are using "ORDER BY RAND()" to fetch multiple rows, not just one ... which is also pretty bad. But in such a case other optimizations are in order ... if you're selecting 30 random items, you wouldn't want to issue 30 queries to the database.