Optimize the following type of queries by using group_by to group aggregates by an interval (e.g., hours, days).
SELECT
date_trunc('day', timestamp) as day,
COUNT(*) as count
FROM
table
WHERE
timestamp >= {} AND timestamp < {}
GROUP BY
date_trunc('day', timestamp)
ORDER BY
day