I have a system that saves statistics for servers in a network. Later a user is able to consume all the data and plan their growth. Thus it is important to summarize the data into a graph ie across an hour, day, week, year, etc.
I'm trying to do something like this:
select created_time / 60, count(*)
from pm_server_stat
group by (created_time / 60);
--with this index
CREATE INDEX pm_server_stat_created_time_60
ON pm_server_stat
USING btree
((created_time / 60));
This is the explain i get
"GroupAggregate (cost=189822.36..213951.06 rows=1206435 width=8)"
" Output: ((created_time / 60)), count(*)"
" -> Sort (cost=189822.36..192838.45 rows=1206435 width=8)"
" Output: created_time, ((created_time / 60))"
" Sort Key: ((pm_server_stat.created_time / 60))"
" -> Seq Scan on public.pm_server_stat (cost=0.00..34967.44 rows=1206435 width=8)"
" Output: created_time, (created_time / 60)"
Does anyone know why this happens? I suspect that the types might be different?