MySQL Forums
Forum List  »  Performance

Is ORDER BY RAND() LIMIT 1 optimized?
Posted by: Markus M.
Date: May 27, 2015 05:40PM

Hi,
I'd like to ask if this query is a special case and would have the performance of "just picking one random row" or if it "needs to sort all rows, like with other LIMIT values" and would later perform worse than a other solution.

That other solution would maybe be first picking a random id in PHP and then doing the query with WHERE id=$the_random_id.

When my table grows to 5000 rows, will it make a difference?

Kind regards,
Markus

Options: ReplyQuote


Subject
Views
Written By
Posted
Is ORDER BY RAND() LIMIT 1 optimized?
6680
May 27, 2015 05:40PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.