The development log check recommendation is very helpful.
However, in this case, randomization occurs at the end of MySQL, and not inside Active Record. To see how the query is executed in MySQL, you can copy the query from the log and paste it into your choice of MySQL (console, graphical interface, etc.) and add "EXPLAIN" to it.
You should get something like:
EXPLAIN SELECT * FROM posts WHERE votes >= 'x' ORDER BY rand() LIMIT n
When I try to execute a similar query in MySQL, they tell me:
Select Type: SIMPLE Using where; Using temporary; Using filesort
Then you need to search for great SO tips on how to optimize MySQL queries. If a problem occurs, adding an index to the vote column can improve performance. situation.
source share