MySQL Forums
Forum List  »  Optimizer & Parser

Re: Close to a million records & query too slow
Posted by: sabelo simelane
Date: March 11, 2010 01:47AM

Rick, thanks for your response and help, really appreciated.

The query :
select a.artistId,
a.name,
( SELECT count(*) FROM play
WHERE dateAndTime >= ?
AND dateAndTime < DATE_ADD(?, INTERVAL 1 DAY)
AND songId = s.songId
) as plays
from artist a,
song s
where (s.artistId = a.artistId)
and (a.isLocal = ?)
order by plays desc;

does not yield the same results as the original. It's supposed to add up all the plays for the artist on the date range. The good news is, the index "INDEX(songId, dateAndTime);" does work fantastically. It has reduced the response time from 9.4 sec to 0.06 which is super. From your advice I've had to alter the original query to this:

from charts.play play, charts.artist artist,
charts.song song
where (play.songId = song.songId)
and (song.artistId = artist.artistId)
and dateAndTime >= ?
AND dateAndTime < DATE_ADD(?, INTERVAL 1 DAY)
and (artist.isLocal = ?)
group by artist.artistId
order by plays desc;

This, with the index you suggested seems to improve the performance dramatically and it solves my problem.

Thanks Rick, your expertise in this field is astounding. Thanks for sharing it with us.

--
Sabelo

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Close to a million records & query too slow
1958
March 11, 2010 01:47AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.