in reply to fetchrow and fetchall question

The fetchrow methods fetch one row (and place it into an array or a hash). The fetchall methods fetch all the selected rows at once, and place them into a an array of arrays, or an array of hashes. For large result sets, you definitely don't want the fetchall methods: you're better off dealing with each row of the results as it comes.

Regardless of which of those two methods you call some databases (MySQL among them) still gather all the results on their end into an array first, and then feed them back to you. The consequence, as you saw, is a very lengthy query.

When I ran into this problem, my solution was to find a field in the table I was fetching that had something resembling a flat distribution over it's range of values, and selected the table in chunks based on that key.

Considering that you're selecting based on the time, I suggest that you make multiple selects with smaller differences between $start_time and $stop_time, (selecting by hours instead of by days, for instance) and then merge the results in your program.