JamesAB
05-31-2015, 08:16 PM
Here's the query I'm trying to optimize:
SELECT *
FROM vb3_jabvideo AS video
LEFT JOIN vb3_attachment AS attachment ON (video.attachmentid = attachment.attachmentid)
LEFT JOIN vb3_user AS user ON (attachment.userid = user.userid)
LEFT JOIN vb3_post AS post ON (post.postid = attachment.postid)
LEFT JOIN vb3_thread AS thread ON (post.threadid = thread.threadid)
WHERE video.isdeleted = 0 AND attachment.visible = 1 AND post.visible = 1 AND thread.visible = 1
ORDER BY RAND()
LIMIT 30
It's currently taking about 2 seconds. There are more than 60,000 rows in the vb3_jabvideo table.
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
SELECT *
FROM vb3_jabvideo AS video
LEFT JOIN vb3_attachment AS attachment ON (video.attachmentid = attachment.attachmentid)
LEFT JOIN vb3_user AS user ON (attachment.userid = user.userid)
LEFT JOIN vb3_post AS post ON (post.postid = attachment.postid)
LEFT JOIN vb3_thread AS thread ON (post.threadid = thread.threadid)
WHERE video.isdeleted = 0 AND attachment.visible = 1 AND post.visible = 1 AND thread.visible = 1
ORDER BY RAND()
LIMIT 30
It's currently taking about 2 seconds. There are more than 60,000 rows in the vb3_jabvideo table.
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