in reply to fetchrow and fetchall question

You are probably better off returning a smaller dataset that will return quicker in a fetchall_arrayref, ie. only the primary key, and then fetch slices through that list.
select ID from hit_table where time between ? and ? order by visit_id, time
Then loop to fetch 20 rows each time using something like :-
select * from hit_table where ID in ( ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?) order by visit_id, time
Hope it helps
UnderMine