When I make a simple benchmark test in a table that has 11.065.763 records. I get the results below:
select sum(t.amount * t.exchange) from table t;
Finalize Aggregate (cost=658027.39..658027.40 rows=1 width=8) (actual time=2391.248..2391.248 rows=1 loops=1)
Buffers: shared hit=25366 read=550786 dirtied=18 written=18
I/O Timings: read=1978.454 write=0.205
-> Gather (cost=658027.17..658027.38 rows=2 width=8) (actual time=2391.100..2391.229 rows=3 loops=1)
Workers Planned: 2
Workers Launched: 2
Buffers: shared hit=25366 read=550786 dirtied=18 written=18
I/O Timings: read=1978.454 write=0.205
-> Partial Aggregate (cost=657027.17..657027.18 rows=1 width=8) (actual time=2377.613..2377.613 rows=1 loops=3)
Buffers: shared hit=24961 read=550759 dirtied=18 written=18
I/O Timings: read=1977.930 write=0.205
-> Parallel Seq Scan on odeme_kaydi ok (cost=0.00..622181.24 rows=4646124 width=16) (actual time=0.084..1972.061 rows=3688816 loops=3)
Buffers: shared hit=24961 read=550759 dirtied=18 written=18
I/O Timings: read=1977.930 write=0.205
Planning time: 0.279 ms
Execution time: 2408.745 ms
select count(t.id) from table t;
Aggregate (cost=489270.14..489270.15 rows=1 width=8) (actual time=12256.560..12256.560 rows=1 loops=1)
Buffers: shared hit=6902688 read=372054 dirtied=32
I/O Timings: read=3067.841
-> Index Only Scan using pk_odeme_kaydi_id on odeme_kaydi ok (cost=0.43..461393.25 rows=11150756 width=8) (actual time=0.169..11583.174 rows=11066478 loops=1)
Heap Fetches: 4085161
Buffers: shared hit=6902688 read=372054 dirtied=32
I/O Timings: read=3067.841
Planning time: 0.110 ms
Execution time: 12256.609 ms
Note: amount field is always greater than 0 in the table. Postgresql version is 9.5.
Is it normal or is there anything tricky?
select count(*) from table t;
?t.id
which is a primary index I assume...