explain.depesz.com

PostgreSQL's explain analyze made readable

Result: xke6 : Optimization for: plan #1GqmF

Settings

Optimization path:

# exclusive inclusive rows x rows loops node
1. 1.359 30,980.774 ↓ 630.0 630 1

Nested Loop (cost=47,413.36..47,414.42 rows=1 width=316) (actual time=8,157.192..30,980.774 rows=630 loops=1)

  • Output: st.id, st.alert_caption, g.establishment_id, h.sensor_id, st_1.ids, u1.measure, (max(h.id)), (min(h.id)), (max(h.received_at)), (min(h.received_at)), ((sum(CASE WHEN ((rank() OVER (?)) = 1) THEN ((((to_json(h.*)) -> u1.measure))::text)::numeric ELSE '0'::numeric END))::double precision), ((max((rank() OVER (?))))::double precision), (sum(((((to_json(h.*)) -> u1.measure))::text)::numeric)), (sum((((((to_json(h.*)) -> u1.measure))::text)::numeric ^ '2'::numeric))), (sum((((((to_json(h.*)) -> u1.measure))::text)::numeric ^ '3'::numeric))), (sum((((((to_json(h.*)) -> u1.measure))::text)::numeric ^ '4'::numeric))), d.mean_x, d.stdevp_x, d.z_x, d.skewp_x, d.ekurtosis_x
  • Buffers: shared hit=15,455 read=9,780
2.          

CTE st

3. 0.015 0.015 ↓ 8.0 8 1

Values Scan on "*VALUES*" (cost=0.00..0.18 rows=1 width=125) (actual time=0.005..0.015 rows=8 loops=1)

  • Output: "*VALUES*".column1, "*VALUES*".column2, "*VALUES*".column3, "*VALUES*".column4, "*VALUES*".column5, "*VALUES*".column6, "*VALUES*".column7, "*VALUES*".column8
  • Filter: (("*VALUES*".column8 = 'heartbeat'::text) AND ((now())::timestamp without time zone <@ "*VALUES*".column4))
4. 1.931 30,951.065 ↓ 630.0 630 1

Nested Loop (cost=47,412.92..47,413.96 rows=1 width=276) (actual time=8,156.811..30,951.065 rows=630 loops=1)

  • Output: g.establishment_id, h.sensor_id, st_1.ids, u1.measure, (max(h.id)), (min(h.id)), (max(h.received_at)), (min(h.received_at)), ((sum(CASE WHEN ((rank() OVER (?)) = 1) THEN ((((to_json(h.*)) -> u1.measure))::text)::numeric ELSE '0'::numeric END))::double precision), ((max((rank() OVER (?))))::double precision), (sum(((((to_json(h.*)) -> u1.measure))::text)::numeric)), (sum((((((to_json(h.*)) -> u1.measure))::text)::numeric ^ '2'::numeric))), (sum((((((to_json(h.*)) -> u1.measure))::text)::numeric ^ '3'::numeric))), (sum((((((to_json(h.*)) -> u1.measure))::text)::numeric ^ '4'::numeric))), st.id, st.alert_caption
  • Join Filter: (st.id = ANY (st_1.ids))
  • Rows Removed by Join Filter: 4,410
  • Buffers: shared hit=15,455 read=9,780
5. 0.014 0.014 ↓ 8.0 8 1

CTE Scan on st (cost=0.00..0.02 rows=1 width=36) (actual time=0.008..0.014 rows=8 loops=1)

  • Output: st.id, st.establishment_id, st.alert_caption, st.effective, st.window_count, st.window_duration, st.window_and, st.type
6. 22,796.320 30,949.120 ↓ 105.0 630 8

GroupAggregate (cost=47,412.92..47,413.74 rows=6 width=240) (actual time=991.561..3,868.640 rows=630 loops=8)

  • Output: g.establishment_id, h.sensor_id, st_1.ids, u1.measure, max(h.id), min(h.id), max(h.received_at), min(h.received_at), (sum(CASE WHEN ((rank() OVER (?)) = 1) THEN ((((to_json(h.*)) -> u1.measure))::text)::numeric ELSE '0'::numeric END))::double precision, (max((rank() OVER (?))))::double precision, sum(((((to_json(h.*)) -> u1.measure))::text)::numeric), sum((((((to_json(h.*)) -> u1.measure))::text)::numeric ^ '2'::numeric)), sum((((((to_json(h.*)) -> u1.measure))::text)::numeric ^ '3'::numeric)), sum((((((to_json(h.*)) -> u1.measure))::text)::numeric ^ '4'::numeric))
  • Group Key: h.sensor_id, st_1.ids, u1.measure, g.establishment_id
  • Buffers: shared hit=15,455 read=9,780
7. 752.630 8,152.800 ↓ 34,153.0 204,918 8

Sort (cost=47,412.92..47,412.93 rows=6 width=124) (actual time=990.013..1,019.100 rows=204,918 loops=8)

  • Output: g.establishment_id, h.sensor_id, st_1.ids, u1.measure, h.id, h.received_at, (rank() OVER (?)), (to_json(h.*))
  • Sort Key: h.sensor_id, st_1.ids, u1.measure, g.establishment_id
  • Sort Method: quicksort Memory: 214,264kB
  • Buffers: shared hit=15,455 read=9,780
8. 47.356 7,400.170 ↓ 34,153.0 204,918 1

Nested Loop (cost=47,412.55..47,412.84 rows=6 width=124) (actual time=3,749.452..7,400.170 rows=204,918 loops=1)

  • Output: g.establishment_id, h.sensor_id, st_1.ids, u1.measure, h.id, h.received_at, (rank() OVER (?)), (to_json(h.*))
  • Buffers: shared hit=15,455 read=9,780
9. 133.768 7,352.814 ↓ 34,153.0 34,153 1

Hash Join (cost=47,412.54..47,412.72 rows=1 width=92) (actual time=3,749.444..7,352.814 rows=34,153 loops=1)

  • Output: h.sensor_id, h.id, h.received_at, (rank() OVER (?)), (to_json(h.*)), g.establishment_id, st_1.ids
  • Hash Cond: (h.gateway_id = g.id)
  • Join Filter: CASE WHEN st_1.window_and THEN (((rank() OVER (?)) <= st_1.window_count) AND (((h0.received_at - h.received_at)) <= st_1.window_duration)) ELSE (((rank() OVER (?)) <= st_1.window_count) OR (((h0.received_at - h.received_at)) <= st_1.window_duration)) END
  • Rows Removed by Join Filter: 691,412
  • Buffers: shared hit=15,455 read=9,780
10. 3,357.703 7,218.989 ↓ 181,391.2 725,565 1

WindowAgg (cost=47,408.11..47,408.21 rows=4 width=76) (actual time=3,749.381..7,218.989 rows=725,565 loops=1)

  • Output: h.id, h.gateway_id, h.sensor_id, h.received_at, (h0.received_at - h.received_at), rank() OVER (?), to_json(h.*)
  • Buffers: shared hit=15,451 read=9,780
11.          

CTE h

12. 1,242.263 1,662.594 ↓ 65,960.5 725,565 1

Hash Join (cost=104.80..47,407.11 rows=11 width=96) (actual time=17.044..1,662.594 rows=725,565 loops=1)

  • Output: h_2.id, h_2.gateway_id, h_2.bru_id, h_2.sensor_id, h_2.sensor_temp_c, h_2.sensor_ts, h_2.sensor_ml, h_2.sensor_vfr, h_2.sensor_flags, h_2.sensor_error, h_2.sensor_sig, h_2.sensor_cdtof, h_2.bru_ts, h_2.bru_temp_c, h_2.bru_baro, h_2.bru_hum, h_2.received_at, h_2.processed_window_at, h_2.bru_addr, h_2.sensor_addr, h_2.processed_missing_at
  • Hash Cond: (ls.line_id = il.line_id)
  • Join Filter: (h_2.received_at <@ il.connected)
  • Rows Removed by Join Filter: 11,851,650
  • Buffers: shared hit=15,451 read=9,780
13. 290.684 419.352 ↓ 998.9 824,102 1

Hash Join (cost=9.05..46,871.39 rows=825 width=100) (actual time=16.057..419.352 rows=824,102 loops=1)

  • Output: h_2.id, h_2.gateway_id, h_2.bru_id, h_2.sensor_id, h_2.sensor_temp_c, h_2.sensor_ts, h_2.sensor_ml, h_2.sensor_vfr, h_2.sensor_flags, h_2.sensor_error, h_2.sensor_sig, h_2.sensor_cdtof, h_2.bru_ts, h_2.bru_temp_c, h_2.bru_baro, h_2.bru_hum, h_2.received_at, h_2.processed_window_at, h_2.bru_addr, h_2.sensor_addr, h_2.processed_missing_at, ls.line_id
  • Hash Cond: (h_2.sensor_id = ls.sensor_id)
  • Join Filter: (h_2.received_at <@ ls.connected)
  • Rows Removed by Join Filter: 1,164
  • Buffers: shared hit=15,422 read=9,780
14. 128.563 128.563 ↑ 1.0 825,270 1

Seq Scan on public.heartbeats h_2 (cost=0.00..33,451.70 rows=825,270 width=96) (actual time=15.934..128.563 rows=825,270 loops=1)

  • Output: h_2.id, h_2.gateway_id, h_2.bru_id, h_2.sensor_id, h_2.sensor_temp_c, h_2.sensor_ts, h_2.sensor_ml, h_2.sensor_vfr, h_2.sensor_flags, h_2.sensor_error, h_2.sensor_sig, h_2.sensor_cdtof, h_2.bru_ts, h_2.bru_temp_c, h_2.bru_baro, h_2.bru_hum, h_2.received_at, h_2.processed_window_at, h_2.bru_addr, h_2.sensor_addr, h_2.processed_missing_at
  • Filter: (h_2.sensor_id IS NOT NULL)
  • Buffers: shared hit=15,419 read=9,780
15. 0.049 0.105 ↑ 1.0 269 1

Hash (cost=5.69..5.69 rows=269 width=24) (actual time=0.104..0.105 rows=269 loops=1)

  • Output: ls.sensor_id, ls.connected, ls.line_id
  • Buckets: 1,024 Batches: 1 Memory Usage: 24kB
  • Buffers: shared hit=3
16. 0.056 0.056 ↑ 1.0 269 1

Seq Scan on public.line_sensors ls (cost=0.00..5.69 rows=269 width=24) (actual time=0.013..0.056 rows=269 loops=1)

  • Output: ls.sensor_id, ls.connected, ls.line_id
  • Buffers: shared hit=3
17. 0.445 0.979 ↓ 1.1 2,715 1

Hash (cost=63.59..63.59 rows=2,573 width=25) (actual time=0.978..0.979 rows=2,715 loops=1)

  • Output: il.connected, il.line_id
  • Buckets: 4,096 Batches: 1 Memory Usage: 190kB
  • Buffers: shared hit=29
18. 0.534 0.534 ↓ 1.1 2,715 1

Seq Scan on public.item_lines il (cost=0.00..63.59 rows=2,573 width=25) (actual time=0.008..0.534 rows=2,715 loops=1)

  • Output: il.connected, il.line_id
  • Filter: ((il.connected_to IS NOT NULL) OR (il.queue_index = '0'::double precision))
  • Rows Removed by Filter: 52
  • Buffers: shared hit=29
19. 629.389 3,861.286 ↓ 181,391.2 725,565 1

Sort (cost=1.00..1.01 rows=4 width=72) (actual time=3,749.353..3,861.286 rows=725,565 loops=1)

  • Output: h.id, h.sensor_id, h.gateway_id, h.received_at, h0.received_at, h.*
  • Sort Key: h.sensor_id, h.id DESC
  • Sort Method: quicksort Memory: 217,305kB
  • Buffers: shared hit=15,451 read=9,780
20. 171.035 3,231.897 ↓ 181,391.2 725,565 1

Hash Join (cost=0.71..0.96 rows=4 width=72) (actual time=2,698.468..3,231.897 rows=725,565 loops=1)

  • Output: h.id, h.sensor_id, h.gateway_id, h.received_at, h0.received_at, h.*
  • Inner Unique: true
  • Hash Cond: (h.sensor_id = h0.sensor_id)
  • Join Filter: (h.id <= h0.id)
  • Buffers: shared hit=15,451 read=9,780
21. 379.453 379.453 ↓ 65,960.5 725,565 1

CTE Scan on h (cost=0.00..0.22 rows=11 width=64) (actual time=17.052..379.453 rows=725,565 loops=1)

  • Output: h.id, h.gateway_id, h.sensor_id, h.received_at, h.*
  • Buffers: shared hit=8,139 read=4,590
22. 0.088 2,681.409 ↓ 9.5 105 1

Hash (cost=0.58..0.58 rows=11 width=16) (actual time=2,681.408..2,681.409 rows=105 loops=1)

  • Output: h0.received_at, h0.sensor_id, h0.id
  • Buckets: 1,024 Batches: 1 Memory Usage: 13kB
  • Buffers: shared hit=7,312 read=5,190
23. 0.051 2,681.321 ↓ 9.5 105 1

Subquery Scan on h0 (cost=0.41..0.58 rows=11 width=16) (actual time=2,505.070..2,681.321 rows=105 loops=1)

  • Output: h0.received_at, h0.sensor_id, h0.id
  • Buffers: shared hit=7,312 read=5,190
24. 78.200 2,681.270 ↓ 9.5 105 1

Unique (cost=0.41..0.47 rows=11 width=16) (actual time=2,505.067..2,681.270 rows=105 loops=1)

  • Output: h_1.id, h_1.sensor_id, h_1.received_at
  • Buffers: shared hit=7,312 read=5,190
25. 543.258 2,603.070 ↓ 65,960.5 725,565 1

Sort (cost=0.41..0.44 rows=11 width=16) (actual time=2,505.065..2,603.070 rows=725,565 loops=1)

  • Output: h_1.id, h_1.sensor_id, h_1.received_at
  • Sort Key: h_1.sensor_id, h_1.received_at DESC
  • Sort Method: quicksort Memory: 58,587kB
  • Buffers: shared hit=7,312 read=5,190
26. 2,059.812 2,059.812 ↓ 65,960.5 725,565 1

CTE Scan on h h_1 (cost=0.00..0.22 rows=11 width=16) (actual time=0.001..2,059.812 rows=725,565 loops=1)

  • Output: h_1.id, h_1.sensor_id, h_1.received_at
  • Buffers: shared hit=7,312 read=5,190
27. 0.004 0.057 ↓ 9.0 9 1

Hash (cost=4.42..4.42 rows=1 width=61) (actual time=0.055..0.057 rows=9 loops=1)

  • Output: g.establishment_id, g.id, st_1.ids, st_1.window_and, st_1.window_count, st_1.window_duration
  • Buckets: 1,024 Batches: 1 Memory Usage: 9kB
  • Buffers: shared hit=4
28. 0.009 0.053 ↓ 9.0 9 1

Hash Join (cost=0.07..4.42 rows=1 width=61) (actual time=0.043..0.053 rows=9 loops=1)

  • Output: g.establishment_id, g.id, st_1.ids, st_1.window_and, st_1.window_count, st_1.window_duration
  • Hash Cond: (g.establishment_id = st_1.establishment_id)
  • Buffers: shared hit=4
29. 0.011 0.011 ↑ 1.0 25 1

Seq Scan on public.gateways g (cost=0.00..4.25 rows=25 width=8) (actual time=0.006..0.011 rows=25 loops=1)

  • Output: g.id, g.establishment_id, g.identifier, g.certificate, g.last_data_at, g.archived, g.certificate_fingerprint256
  • Buffers: shared hit=4
30. 0.004 0.033 ↓ 8.0 8 1

Hash (cost=0.06..0.06 rows=1 width=57) (actual time=0.032..0.033 rows=8 loops=1)

  • Output: st_1.ids, st_1.establishment_id, st_1.window_and, st_1.window_count, st_1.window_duration
  • Buckets: 1,024 Batches: 1 Memory Usage: 9kB
31. 0.002 0.029 ↓ 8.0 8 1

Subquery Scan on st_1 (cost=0.03..0.06 rows=1 width=57) (actual time=0.025..0.029 rows=8 loops=1)

  • Output: st_1.ids, st_1.establishment_id, st_1.window_and, st_1.window_count, st_1.window_duration
32. 0.013 0.027 ↓ 8.0 8 1

HashAggregate (cost=0.03..0.05 rows=1 width=57) (actual time=0.024..0.027 rows=8 loops=1)

  • Output: st_2.establishment_id, st_2.window_count, st_2.window_duration, st_2.window_and, array_agg(st_2.id)
  • Group Key: st_2.establishment_id, st_2.window_count, st_2.window_duration, st_2.window_and
33. 0.014 0.014 ↓ 8.0 8 1

CTE Scan on st st_2 (cost=0.00..0.02 rows=1 width=29) (actual time=0.000..0.014 rows=8 loops=1)

  • Output: st_2.id, st_2.establishment_id, st_2.alert_caption, st_2.effective, st_2.window_count, st_2.window_duration, st_2.window_and, st_2.type
34. 0.000 0.000 ↑ 1.0 6 34,153

Function Scan on pg_catalog.unnest u1 (cost=0.00..0.06 rows=6 width=32) (actual time=0.000..0.000 rows=6 loops=34,153)

  • Output: u1.measure
  • Function Call: unnest('{sensor_temp_c,sensor_sig,sensor_cdtof,bru_temp_c,bru_baro,bru_hum}'::text[])
35. 28.350 28.350 ↑ 1.0 1 630

Function Scan on public.distribution_statistics d (cost=0.26..0.27 rows=1 width=40) (actual time=0.045..0.045 rows=1 loops=630)

  • Output: d.mean_x, d.stdevp_x, d.z_x, d.skewp_x, d.ekurtosis_x
  • Function Call: distribution_statistics((((max((rank() OVER (?))))::double precision))::integer, ((sum(CASE WHEN ((rank() OVER (?)) = 1) THEN ((((to_json(h.*)) -> u1.measure))::text)::numeric ELSE '0'::numeric END))::double precision), ((sum(((((to_json(h.*)) -> u1.measure))::text)::numeric)))::double precision, ((sum((((((to_json(h.*)) -> u1.measure))::text)::numeric ^ '2'::numeric))))::double precision, ((sum((((((to_json(h.*)) -> u1.measure))::text)::numeric ^ '3'::numeric))))::double precision, ((sum((((((to_json(h.*)) -> u1.measure))::text)::numeric ^ '4'::numeric))))::double precision)
Planning time : 1.123 ms
Execution time : 31,138.414 ms