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:
PLAIN TEXT SQL:
- 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 it in the end.
The reason for slowness was of course huge temporary table was required (there were about 5 million of distinct pages visited during that day) which resulted in on disk temporary table which as we know quite slow.
Of course it would be possible to allocate more memory to the temporary table or switch to filesort method and get result faster.
I however picked another road which is quite helpful in similar cases - I did not need exact result but …
[Read more]