I have a database of observations. Each observation contains a station identifier among other things. In order to update our station list, I want to know which stations have observed more than 720 times in the past 30 days. But I noticed something funny. Just for kicks I was breaking it up by starting letter. For example,
SELECT station,COUNT(station) FROM observations WHERE station > "C" AND
station < "D" GROUP BY station HAVING COUNT(station) > 720 LIMIT 100;
This query took 1.51 seconds to complete, returning 100 rows. Next I put
SELECT station,COUNT(station) FROM observations WHERE station > "C" AND
station < "D" GROUP BY station HAVING COUNT(station) > 720 LIMIT 200;
This query took 5.58 seconds. Okay I thought it probably shouldn't take that long, but I'll live. Finally, I tried
SELECT station,COUNT(station) FROM observations WHERE station > "C" AND
station < "D" GROUP BY station HAVING COUNT(station) > 720 LIMIT 300;
This took a whopping 4 minutes and 28 seconds to complete!
I wonder if anyone has a theoretical explanation as to why the counting appears to "get slower faster" as I up the limit on the query. Also, I am not a MySQL professional, I just use it to get things into my csv files so I can go after them with C++. Is there anything in my query itself that is causing problems here? Or is COUNT() just slow?