So, for my Survival Games Minecraft plugin (think Hunger Games) I have a web based stats system. It all works perfect, the only issue is when I get tons of data in the databases, the sql queries get extremely slow. I was wondering if anyone could help with optimizations on them. Here is the first query. Im assuming its all the sum()'s but im not sure of a better way to do this.
Code:
Now that works fine until you get millions of results in the database, and it gets slow. to see more of what this does http://mc-sg.org/stats
Code:
$sql = 'SELECT `player`,sum(kills) as tkills ,sum(death) as tdeath,sum(time) as ttime, sum(points) as total_points , sum(position) as tpos, sum(position = 1) as wins, count(*) as tgames, sum(position)/count(*) as avgpos,sum(kills)/sum(death) as kd FROM '.$dbprefix.'playerstats GROUP BY player ORDER BY '.$sort.' desc LIMIT '.($p*$per_page).','.$per_page;
Now that works fine until you get millions of results in the database, and it gets slow. to see more of what this does http://mc-sg.org/stats