I have a query that takes about 9 seconds. It makes my website very slow. Could anyone point me in the right direction on how to optimize it for better performance. Don't judge the syntax, it's pretty ugly :$
我有一个大约需要9秒的查询。它使我的网站很慢。任何人都可以指出我如何优化它以获得更好的性能。不要判断语法,这很难看:$
SELECT songs.id, count(votes.song_id) AS votes
FROM songs, songs_genre, votes
WHERE votes.song_id=songs.id
AND songs_genre.genre_id IN ('$genre_ids')
AND songs.id=songs_genre.song_id
AND votes.date<=DATE_ADD(CURDATE(), INTERVAL + 1 DAY)
AND votes.date>=DATE_ADD(CURDATE(), INTERVAL - 3 MONTH)
GROUP BY votes.song_id
ORDER BY votes DESC limit 36
1 个解决方案
#1
0
The query looks good, I would say that only thing that would improve the performance offhand is proper indexing on votes or songs id.
查询看起来不错,我会说只有能够改善性能的东西才能正确地对投票或歌曲id进行索引。
#1
0
The query looks good, I would say that only thing that would improve the performance offhand is proper indexing on votes or songs id.
查询看起来不错,我会说只有能够改善性能的东西才能正确地对投票或歌曲id进行索引。