We are running a stats site for a bunch of games, but after the log has tipped over 100 megs, things are starting to slow down, so we need to optimize our queries.
However, we've found out that what we thought was a simple query, takes about 1.5 secs:
SELECT handle,
(
SELECT COUNT(*)
FROM kills
WHERE killer=p.handle
AND k_team != c_team
AND gid=p.gid
) AS kills
FROM players as p
WHERE gid="3245"
AND team="axis"
ORDER BY kills DESC LIMIT 0, 10;
This produces a result list for one of the teams.
Table kills and players consists of 36000 and 4000 rows respectfully.
Why is that query taking so long and how can it be optimize? Should we perhaps look into JOIN?
Best regards, Laka