explain.depesz.com

PostgreSQL's explain analyze made readable

Result: oOSU : Optimization for: plan #1GqmF

Settings

Optimization path:

# exclusive inclusive rows x rows loops node
1. 0.531 31,261.029 ↓ 630.0 630 1

Nested Loop (cost=47,413.36..47,414.42 rows=1 width=316) (actual time=8,152.997..31,261.029 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,519 read=9,716
2.          

CTE st

3. 0.042 0.042 ↓ 8.0 8 1

Values Scan on "*VALUES*" (cost=0.00..0.18 rows=1 width=125) (actual time=0.030..0.042 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.853 31,236.558 ↓ 630.0 630 1

Nested Loop (cost=47,412.92..47,413.96 rows=1 width=276) (actual time=8,152.689..31,236.558 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,519 read=9,716
5. 0.041 0.041 ↓ 8.0 8 1

CTE Scan on st (cost=0.00..0.02 rows=1 width=36) (actual time=0.032..0.041 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. 23,047.248 31,234.664 ↓ 105.0 630 8

GroupAggregate (cost=47,412.92..47,413.74 rows=6 width=240) (actual time=995.623..3,904.333 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,519 read=9,716
7. 633.443 8,187.416 ↓ 34,153.0 204,918 8

Sort (cost=47,412.92..47,412.93 rows=6 width=124) (actual time=994.185..1,023.427 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,519 read=9,716
8. 45.042 7,553.973 ↓ 34,153.0 204,918 1

Nested Loop (cost=47,412.55..47,412.84 rows=6 width=124) (actual time=3,912.637..7,553.973 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,519 read=9,716
9. 131.998 7,508.931 ↓ 34,153.0 34,153 1

Hash Join (cost=47,412.54..47,412.72 rows=1 width=92) (actual time=3,912.629..7,508.931 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,519 read=9,716
10. 3,355.076 7,376.843 ↓ 181,391.2 725,565 1

WindowAgg (cost=47,408.11..47,408.21 rows=4 width=76) (actual time=3,912.533..7,376.843 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,515 read=9,716
11.          

CTE h

12. 1,437.206 1,921.876 ↓ 65,960.5 725,565 1

Hash Join (cost=104.80..47,407.11 rows=11 width=96) (actual time=18.383..1,921.876 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,515 read=9,716
13. 336.703 483.679 ↓ 998.9 824,102 1

Hash Join (cost=9.05..46,871.39 rows=825 width=100) (actual time=17.382..483.679 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,486 read=9,716
14. 146.870 146.870 ↑ 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=17.261..146.870 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,483 read=9,716
15. 0.049 0.106 ↑ 1.0 269 1

Hash (cost=5.69..5.69 rows=269 width=24) (actual time=0.106..0.106 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.057 0.057 ↑ 1.0 269 1

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

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

Hash (cost=63.59..63.59 rows=2,573 width=25) (actual time=0.991..0.991 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.536 0.536 ↓ 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.007..0.536 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. 589.408 4,021.767 ↓ 181,391.2 725,565 1

Sort (cost=1.00..1.01 rows=4 width=72) (actual time=3,912.506..4,021.767 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,515 read=9,716
20. 138.744 3,432.359 ↓ 181,391.2 725,565 1

Hash Join (cost=0.71..0.96 rows=4 width=72) (actual time=3,001.180..3,432.359 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,515 read=9,716
21. 310.833 310.833 ↓ 65,960.5 725,565 1

CTE Scan on h (cost=0.00..0.22 rows=11 width=64) (actual time=18.390..310.833 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.052 2,982.782 ↓ 9.5 105 1

Hash (cost=0.58..0.58 rows=11 width=16) (actual time=2,982.781..2,982.782 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,376 read=5,126
23. 0.033 2,982.730 ↓ 9.5 105 1

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

  • Output: h0.received_at, h0.sensor_id, h0.id
  • Buffers: shared hit=7,376 read=5,126
24. 75.961 2,982.697 ↓ 9.5 105 1

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

  • Output: h_1.id, h_1.sensor_id, h_1.received_at
  • Buffers: shared hit=7,376 read=5,126
25. 521.772 2,906.736 ↓ 65,960.5 725,565 1

Sort (cost=0.41..0.44 rows=11 width=16) (actual time=2,820.030..2,906.736 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,376 read=5,126
26. 2,384.964 2,384.964 ↓ 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,384.964 rows=725,565 loops=1)

  • Output: h_1.id, h_1.sensor_id, h_1.received_at
  • Buffers: shared hit=7,376 read=5,126
27. 0.005 0.090 ↓ 9.0 9 1

Hash (cost=4.42..4.42 rows=1 width=61) (actual time=0.088..0.090 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.032 0.085 ↓ 9.0 9 1

Hash Join (cost=0.07..4.42 rows=1 width=61) (actual time=0.059..0.085 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.016 0.016 ↑ 1.0 25 1

Seq Scan on public.gateways g (cost=0.00..4.25 rows=25 width=8) (actual time=0.008..0.016 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.037 ↓ 8.0 8 1

Hash (cost=0.06..0.06 rows=1 width=57) (actual time=0.036..0.037 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.033 ↓ 8.0 8 1

Subquery Scan on st_1 (cost=0.03..0.06 rows=1 width=57) (actual time=0.029..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
32. 0.014 0.031 ↓ 8.0 8 1

HashAggregate (cost=0.03..0.05 rows=1 width=57) (actual time=0.028..0.031 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.017 0.017 ↓ 8.0 8 1

CTE Scan on st st_2 (cost=0.00..0.02 rows=1 width=29) (actual time=0.000..0.017 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. 23.940 23.940 ↑ 1.0 1 630

Function Scan on public.distribution_statistics d (cost=0.26..0.27 rows=1 width=40) (actual time=0.037..0.038 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.106 ms
Execution time : 31,423.526 ms