简体   繁体   中英

How to optimize this mySQL query in terms of performance?

How can I optimize the follow query ?

select
hash,page,timestamp, count(*) as total
from behaviour
group by hash, page
having total > 2 AND timestamp >= Now() - interval 5 minute

Thank you

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM