QUERY PLAN
GroupAggregate (cost=21267.11..21286.98 rows=461 width=31) (actual time=1.711..1.712 rows=1 loops=1)
Group Key: (date_trunc(‘month’::text, timezone(‘Europe/Berlin’::text, m.”timestamp”))), d.sub_type
-> Sort (cost=21267.11..21268.91 rows=719 width=35) (actual time=1.564..1.591 rows=719 loops=1)
Sort Key: (date_trunc(‘month’::text, timezone(‘Europe/Berlin’::text, m.”timestamp”))), d.sub_type
Sort Method: quicksort Memory: 69kB
-> Nested Loop (cost=70.03..21233.00 rows=719 width=35) (actual time=0.483..1.454 rows=719 loops=1)
-> Index Scan using idx_devices_id on devices d (cost=0.28..8.30 rows=1 width=27) (actual time=0.017..0.018 rows=1 loops=1)
Index Cond: (id = ‘c28ace1e-cf28-4d2f-a7d3-9bc8631cd379’::uuid)
-> Bitmap Heap Scan on measurements m (cost=69.75..21213.91 rows=719 width=32) (actual time=0.240..0.994 rows=719 loops=1)
Recheck Cond: (device_id = ‘c28ace1e-cf28-4d2f-a7d3-9bc8631cd379’::uuid)
Filter: ((“timestamp” >= ‘2024-01-01 11:00:00+00’::timestamp with time zone) AND (“timestamp” < ‘2024-01-31 11:00:00+00’::timestamp with time zone) AND (type = 4))
Rows Removed by Filter: 5241
Heap Blocks: exact=50
-> Bitmap Index Scan on idx_measurements_device_id (cost=0.00..69.57 rows=6018 width=0) (actual time=0.224..0.224 rows=5960 loops=1)
Index Cond: (device_id = ‘c28ace1e-cf28-4d2f-a7d3-9bc8631cd379’::uuid)
Planning Time: 0.697 ms
Execution Time: 1.766 ms
(17 rows)
QUERY PLAN
GroupAggregate (cost=21267.11..21286.98 rows=461 width=31) (actual time=0.897..0.898 rows=1 loops=1)
Group Key: (date_trunc(‘month’::text, timezone(‘Europe/Berlin’::text, m.”timestamp”))), d.sub_type
-> Sort (cost=21267.11..21268.91 rows=719 width=35) (actual time=0.795..0.831 rows=719 loops=1)
Sort Key: (date_trunc(‘month’::text, timezone(‘Europe/Berlin’::text, m.”timestamp”))), d.sub_type
Sort Method: quicksort Memory: 69kB
-> Nested Loop (cost=70.03..21233.00 rows=719 width=35) (actual time=0.178..0.718 rows=719 loops=1)
-> Index Scan using idx_devices_id on devices d (cost=0.28..8.30 rows=1 width=27) (actual time=0.004..0.005 rows=1 loops=1)
Index Cond: (id = ‘c28ace1e-cf28-4d2f-a7d3-9bc8631cd379’::uuid)
-> Bitmap Heap Scan on measurements m (cost=69.75..21213.91 rows=719 width=32) (actual time=0.081..0.457 rows=719 loops=1)
Recheck Cond: (device_id = ‘c28ace1e-cf28-4d2f-a7d3-9bc8631cd379’::uuid)
Filter: ((“timestamp” >= ‘2024-01-01 11:00:00+00’::timestamp with time zone) AND (“timestamp” < ‘2024-01-31 11:00:00+00’::timestamp with time zone) AND (type = 4))
Rows Removed by Filter: 5241
Heap Blocks: exact=50
-> Bitmap Index Scan on idx_measurements_device_id (cost=0.00..69.57 rows=6018 width=0) (actual time=0.073..0.073 rows=5960 loops=1)
Index Cond: (device_id = ‘c28ace1e-cf28-4d2f-a7d3-9bc8631cd379’::uuid)
Planning Time: 0.336 ms
Execution Time: 0.929 ms
(17 rows)
QUERY PLAN
GroupAggregate (cost=21267.11..21286.98 rows=461 width=31) (actual time=0.873..0.873 rows=1 loops=1)
Group Key: (date_trunc(‘month’::text, timezone(‘Europe/Berlin’::text, m.”timestamp”))), d.sub_type
-> Sort (cost=21267.11..21268.91 rows=719 width=35) (actual time=0.794..0.813 rows=719 loops=1)
Sort Key: (date_trunc(‘month’::text, timezone(‘Europe/Berlin’::text, m.”timestamp”))), d.sub_type
Sort Method: quicksort Memory: 69kB
-> Nested Loop (cost=70.03..21233.00 rows=719 width=35) (actual time=0.168..0.717 rows=719 loops=1)
-> Index Scan using idx_devices_id on devices d (cost=0.28..8.30 rows=1 width=27) (actual time=0.004..0.004 rows=1 loops=1)
Index Cond: (id = ‘c28ace1e-cf28-4d2f-a7d3-9bc8631cd379’::uuid)
-> Bitmap Heap Scan on measurements m (cost=69.75..21213.91 rows=719 width=32) (actual time=0.071..0.457 rows=719 loops=1)
Recheck Cond: (device_id = ‘c28ace1e-cf28-4d2f-a7d3-9bc8631cd379’::uuid)
Filter: ((“timestamp” >= ‘2024-01-01 11:00:00+00’::timestamp with time zone) AND (“timestamp” < ‘2024-01-31 11:00:00+00’::timestamp with time zone) AND (type = 4))
Rows Removed by Filter: 5241
Heap Blocks: exact=50
-> Bitmap Index Scan on idx_measurements_device_id (cost=0.00..69.57 rows=6018 width=0) (actual time=0.063..0.063 rows=5960 loops=1)
Index Cond: (device_id = ‘c28ace1e-cf28-4d2f-a7d3-9bc8631cd379’::uuid)
Planning Time: 0.304 ms
Execution Time: 0.903 ms
(17 rows)
—————————————————————————————————————
Time (mean ± σ): 98.1 ms ± 28.1 ms [User: 30.7 ms, System: 11.1 ms]Range (min … max): 75.6 ms … 129.5 ms 3 runs
—————————————————————————————————————
I’m using hyperfine to benchmark the performance of my query in PostgreSQL. I used --runs 3
option to run it three times. As you can see, the execution time for all the three times I’m running the query takes 1.766, 0.929 and 0.903 ms respectively. My question is, why is the mean = 98,1 ms? What does this mean represent? Because it does not make any sense that the execution time is between 0,9 ms – 1,7 ms, while the mean of them is 98.1 ms. I tested to execute this same query in Postico and it took 0.903 ms. Im just curious what the mean represent if it does not represent the execution average time.
Nuh Jama is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.