When your goal is to optimize application performance it is very important to understand what goal do you really have. If you do not have a good understanding of the goal your performance optimization effort may well still bring its results but you may waste a lot of time before you reach same results as [...]
Speeding up GROUP BY if you want aproximate results
Doing performance analyzes today I wanted to count how many hits come to the pages which get more than couple of visits per day. We had SQL logs in the database so It was pretty simple query:
1 | select sum(cnt) from (select count(*) cnt from performance_log_080306 group by page having cnt>2) pv; |
Unfortunately this query ran for over half an hour badly overloaded server and I had to kill [...]

