Hi all!
I'd like to optimize my queries so i look into mysql-slow.log
.
Most of my slow queries contains ORDER BY RAND()
. I cannot find a real solution to resolve this problem. Theres is a possible solution at MySQLPerformanceBlog but i don't think this is enough. On poorly optimized (or frequently updated, user managed) tables it doesn't work or i need to run two or more queries before i can select my PHP
-generated random row.
Is there any solution for this issue?
Thanks!
A dummy example:
SELECT accomodation.ac_id,
accomodation.ac_status,
accomodation.ac_name,
accomodation.ac_status,
accomodation.ac_images
FROM accomodation, accomodation_category
WHERE accomodation.ac_status != 'draft'
AND accomodation.ac_category = accomodation_category.acat_id
AND accomodation_category.acat_slug != 'vendeglatohely'
AND ac_images != 'b:0;'
ORDER BY
RAND()
LIMIT 1