explain.depesz.com

PostgreSQL's explain analyze made readable

Result: SEFl

Settings

Optimization(s) for this plan:

# exclusive inclusive rows x rows loops node
1. 0.846 68,152.673 ↓ 630.0 630 1

Nested Loop (cost=47,424.64..47,425.70 rows=1 width=312) (actual time=41,624.414..68,152.673 rows=630 loops=1)

2.          

CTE st

3. 0.018 0.018 ↓ 8.0 8 1

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

  • Filter: ((column8 = 'heartbeat'::text) AND ((now())::timestamp without time zone <@ column4))
4. 2.271 68,122.217 ↓ 630.0 630 1

Nested Loop (cost=47,424.20..47,425.24 rows=1 width=272) (actual time=41,623.953..68,122.217 rows=630 loops=1)

  • Join Filter: (st.id = ANY ((array_agg(st_1.id))))
  • Rows Removed by Join Filter: 4,410
5. 0.018 0.018 ↓ 8.0 8 1

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

6. 26,097.472 68,119.928 ↓ 105.0 630 8

GroupAggregate (cost=47,424.20..47,425.03 rows=6 width=240) (actual time=5,287.196..8,514.991 rows=630 loops=8)

  • Group Key: g.establishment_id, h.sensor_id, (array_agg(st_1.id)), u1.measure
7. 1,349.501 42,022.456 ↓ 34,153.0 204,918 8

Sort (cost=47,424.20..47,424.22 rows=6 width=124) (actual time=5,188.748..5,252.807 rows=204,918 loops=8)

  • Sort Key: g.establishment_id, h.sensor_id, (array_agg(st_1.id)), u1.measure
  • Sort Method: external sort Disk: 111,184kB
8. 23.662 40,672.955 ↓ 34,153.0 204,918 1

Nested Loop (cost=47,408.70..47,424.12 rows=6 width=124) (actual time=5,957.685..40,672.955 rows=204,918 loops=1)

9. 63.788 40,615.140 ↓ 34,153.0 34,153 1

Nested Loop (cost=47,408.70..47,424.00 rows=1 width=92) (actual time=5,957.678..40,615.140 rows=34,153 loops=1)

  • Join Filter: (st_1.establishment_id = g.establishment_id)
  • Rows Removed by Join Filter: 222,223
10. 50.044 40,294.976 ↓ 128,188.0 256,376 1

Nested Loop (cost=47,408.56..47,423.39 rows=2 width=96) (actual time=4,924.146..40,294.976 rows=256,376 loops=1)

11. 163.700 39,988.556 ↓ 128,188.0 256,376 1

Nested Loop (cost=47,408.42..47,423.01 rows=2 width=96) (actual time=4,924.141..39,988.556 rows=256,376 loops=1)

12. 574.643 39,568.480 ↓ 128,188.0 256,376 1

Nested Loop (cost=47,408.14..47,408.40 rows=2 width=92) (actual time=4,924.125..39,568.480 rows=256,376 loops=1)

  • Join Filter: CASE WHEN st_1.window_flag 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: 5,548,144
13. 0.043 0.069 ↓ 8.0 8 1

GroupAggregate (cost=0.03..0.06 rows=1 width=57) (actual time=0.027..0.069 rows=8 loops=1)

  • Group Key: st_1.establishment_id, st_1.window_count, st_1.window_duration, st_1.window_flag
14. 0.010 0.026 ↓ 8.0 8 1

Sort (cost=0.03..0.04 rows=1 width=29) (actual time=0.022..0.026 rows=8 loops=1)

  • Sort Key: st_1.establishment_id, st_1.window_count, st_1.window_duration, st_1.window_flag
  • Sort Method: quicksort Memory: 25kB
15. 0.016 0.016 ↓ 8.0 8 1

CTE Scan on st st_1 (cost=0.00..0.02 rows=1 width=29) (actual time=0.001..0.016 rows=8 loops=1)

16. 32,994.168 38,993.768 ↓ 181,391.2 725,565 8

WindowAgg (cost=47,408.11..47,408.21 rows=4 width=72) (actual time=615.520..4,874.221 rows=725,565 loops=8)

17.          

CTE h

18. 1,592.515 2,116.982 ↓ 65,960.5 725,565 1

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

  • Hash Cond: (ls.line_id = il.line_id)
  • Join Filter: (h_2.received_at <@ il.connected)
  • Rows Removed by Join Filter: 11,851,650
19. 364.298 523.495 ↓ 998.9 824,102 1

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

  • Hash Cond: (h_2.sensor_id = ls.sensor_id)
  • Join Filter: (h_2.received_at <@ ls.connected)
  • Rows Removed by Join Filter: 1,164
20. 159.091 159.091 ↑ 1.0 825,270 1

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

  • Filter: (sensor_id IS NOT NULL)
21. 0.050 0.106 ↑ 1.0 269 1

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

  • Buckets: 1,024 Batches: 1 Memory Usage: 24kB
22. 0.056 0.056 ↑ 1.0 269 1

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

23. 0.437 0.972 ↓ 1.1 2,715 1

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

  • Buckets: 4,096 Batches: 1 Memory Usage: 190kB
24. 0.535 0.535 ↓ 1.1 2,715 1

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

  • Filter: ((connected_to IS NOT NULL) OR (queue_index = '0'::double precision))
  • Rows Removed by Filter: 52
25. 2,038.265 5,999.600 ↓ 181,391.2 725,565 8

Sort (cost=1.00..1.01 rows=4 width=64) (actual time=615.509..749.950 rows=725,565 loops=8)

  • Sort Key: h.sensor_id, h.id DESC
  • Sort Method: external sort Disk: 110,136kB
26. 201.269 3,961.335 ↓ 181,391.2 725,565 1

Hash Join (cost=0.71..0.96 rows=4 width=64) (actual time=3,284.142..3,961.335 rows=725,565 loops=1)

  • Hash Cond: (h.sensor_id = h0.sensor_id)
  • Join Filter: (h.id <= h0.id)
27. 492.753 492.753 ↓ 65,960.5 725,565 1

CTE Scan on h (cost=0.00..0.22 rows=11 width=56) (actual time=16.814..492.753 rows=725,565 loops=1)

28. 0.190 3,267.313 ↓ 9.5 105 1

Hash (cost=0.58..0.58 rows=11 width=16) (actual time=3,267.311..3,267.313 rows=105 loops=1)

  • Buckets: 1,024 Batches: 1 Memory Usage: 13kB
29. 0.090 3,267.123 ↓ 9.5 105 1

Subquery Scan on h0 (cost=0.41..0.58 rows=11 width=16) (actual time=3,069.155..3,267.123 rows=105 loops=1)

30. 73.590 3,267.033 ↓ 9.5 105 1

Unique (cost=0.41..0.47 rows=11 width=16) (actual time=3,069.153..3,267.033 rows=105 loops=1)

31. 479.939 3,193.443 ↓ 65,960.5 725,565 1

Sort (cost=0.41..0.44 rows=11 width=16) (actual time=3,069.152..3,193.443 rows=725,565 loops=1)

  • Sort Key: h_1.sensor_id, h_1.received_at DESC
  • Sort Method: external merge Disk: 18,512kB
32. 2,713.504 2,713.504 ↓ 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,713.504 rows=725,565 loops=1)

33. 256.376 256.376 ↑ 1.0 1 256,376

Index Scan using sensors_pkey on sensors s (cost=0.28..7.29 rows=1 width=8) (actual time=0.001..0.001 rows=1 loops=256,376)

  • Index Cond: (id = h.sensor_id)
34. 256.376 256.376 ↑ 1.0 1 256,376

Index Scan using brus_pkey on brus b (cost=0.14..0.19 rows=1 width=8) (actual time=0.001..0.001 rows=1 loops=256,376)

  • Index Cond: (id = s.bru_id)
35. 256.376 256.376 ↑ 1.0 1 256,376

Index Scan using gateways_pkey on gateways g (cost=0.14..0.29 rows=1 width=8) (actual time=0.001..0.001 rows=1 loops=256,376)

  • Index Cond: (id = b.gateway_id)
36. 34.153 34.153 ↑ 1.0 6 34,153

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

37. 29.610 29.610 ↑ 1.0 1 630

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

Planning time : 2.068 ms
Execution time : 68,175.811 ms