-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4.2.sql
46 lines (40 loc) · 1.26 KB
/
4.2.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
EXPLAIN ANALYZE SELECT
location_id, avg(temp_celcius)
FROM
time_series.location_temp
GROUP BY
location_id;
/*
Query Plan
Finalize GroupAggregate (cost=7337.44..7465.36 rows=500 width=38)
Group Key: location_id
-> Gather Merge (cost=7337.44..7454.11 rows=1000 width=38)
Workers Planned: 2
-> Sort (cost=6337.41..6338.66 rows=500 width=38)
Sort Key: location_id
-> Partial HashAggregate (cost=6310.00..6315.00 rows=500 width=38)
Group Key: location_id
-> Parallel Seq Scan on location_temp (cost=0.00..5268.33 rows=208333 width=10)
Planning Time: 0.180 ms
Execution Time: 192.387 ms
*/
CREATE INDEX idx_loc_temp_location ON
time_series.location_temp(location_id)
EXPLAIN SELECT
location_id, avg(temp_celcius)
FROM
time_series.location_temp
WHERE
location_id = 'loc2'
GROUP BY
location_id
/*
Query Plan
GroupAggregate (cost=20.14..2145.65 rows=432 width=38)
Group Key: location_id
-> Bitmap Heap Scan on location_temp(cost=20.14..2135.27 rows=9...)
Recheck Cond: ((location_id)::text = 'loc2'::text)
-> Bitmap Index Scan on idx_loc_temp_location (cost=0.00..19.89...)
Index Cond: ((location_id)::text = 'loc2'::text)
*/
DROP INDEX time_series.idx_loc_temp_location;