![]() |
Need help optimizing a mySQL query
Here's the query I'm trying to optimize:
Code:
SELECT * I believe the heart of the problem is ORDER BY RAND() Any mySQL experts out there that could offer advice for optimizing this query or another solution for selecting 30 random rows from this table? Thanks for your help, James |
That's a good question to look up on stackoverflow.com. There's one answer here: http://stackoverflow.com/questions/1...-by-rand-query. Basically, do a query (if you need to) to get the number of rows in the table, then do 5 queries with a random OFFSET. But you have 30 to get, so I guess you'd need to test to see if doing 30 separate queries will be faster that the one you have. Edit: oh, well, your query has some things it checks in the "WHERE', so I guess you'd have to be prepared to do more than 30 queries so that if the conditions for a given row aren't true you can get another. So maybe that's not really a good solution for you.
Also, unless you really need each page request to get a different 30 random rows, you could cache the results and only do the query once a minute, for example. |
Thanks for the advice. I've started doing some reading, but haven't tried coding anything for this yet. I also came accross this link:
http://jan.kneschke.de/projects/mysql/order-by-rand/ I'm not sure if using a stored procedure would be suitable for what I need or not. Thanks, James |
All times are GMT. The time now is 02:09 AM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|