ernest1a Posted March 28, 2010 Share Posted March 28, 2010 I have a situation where I need to display from more than 200.000 rows 10 results in a website header on each page. I would like to show random 10 results from all rows that are matching WHERE condition. LIMIT 10 is very fast, but if I add ORDER BY rand() it makes slow everything a lot, about the same time as if I didn't limit results. But the problem is I need to show random 10 results and not everytime first 10 results. Another case is the same with exception that I need to include also pagination. I hope anybody have any idea at least for first case how to optimize this query. Thank you! Link to comment https://forums.phpfreaks.com/topic/196792-order-by-limit-performance/ Share on other sites More sharing options...
fenway Posted March 28, 2010 Share Posted March 28, 2010 Finding a random X of Y where X <<<< Y can never be fast. Link to comment https://forums.phpfreaks.com/topic/196792-order-by-limit-performance/#findComment-1033153 Share on other sites More sharing options...
andrewgauger Posted March 29, 2010 Share Posted March 29, 2010 http://www.titov.net/2005/09/21/do-not-use-order-by-rand-or-how-to-get-random-rows-from-table/ Link to comment https://forums.phpfreaks.com/topic/196792-order-by-limit-performance/#findComment-1033609 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.