How can I optimize the follow query ?
hash,page,timestamp, count(*) as total
group by hash, page
having total > 2 AND timestamp >= Now() - interval 5 minute
This query it's not wrong. Maybe with a bigger volume, you could have a problem with performance. Try use "WHERE CONDITIONS" always. (In your context, i don't know if is possible). Another tip, is EXPLAIN on your query! Use "explain" before your query. (explain select hash, timestamp, count(*)........). In this way, you can discover how many results your query is returned.