explain.depesz.com

PostgreSQL's explain analyze made readable

Result: J3ki : Optimization for: plan #SEFl

Settings

Optimization path:

# exclusive inclusive rows x rows loops node
1. 1.153 43,045.487 ↓ 630.0 630 1

Nested Loop (cost=47,424.64..47,425.70 rows=1 width=312) (actual time=35,436.537..43,045.487 rows=630 loops=1)

2.          

CTE st

3. 0.045 0.045 ↓ 8.0 8 1

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

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

Nested Loop (cost=47,424.20..47,425.24 rows=1 width=272) (actual time=35,436.058..43,016.614 rows=630 loops=1)

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

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

6. 7,436.080 43,014.448 ↓ 105.0 630 8

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

  • Group Key: g.establishment_id, h.sensor_id, (array_agg(st_1.id)), u1.measure
7. 331.349 35,578.368 ↓ 9,798.0 58,788 8

Sort (cost=47,424.20..47,424.22 rows=6 width=124) (actual time=4,429.384..4,447.296 rows=58,788 loops=8)

  • Sort Key: g.establishment_id, h.sensor_id, (array_agg(st_1.id)), u1.measure
  • Sort Method: external sort Disk: 31,864kB
8. 5.507 35,247.019 ↓ 9,798.0 58,788 1

Nested Loop (cost=47,408.70..47,424.12 rows=6 width=124) (actual time=5,227.001..35,247.019 rows=58,788 loops=1)

9. 5.370 35,231.714 ↓ 9,798.0 9,798 1

Nested Loop (cost=47,408.70..47,424.00 rows=1 width=92) (actual time=5,226.995..35,231.714 rows=9,798 loops=1)

  • Join Filter: (st_1.establishment_id = g.establishment_id)
  • Rows Removed by Join Filter: 67,888
10. 3.712 35,148.658 ↓ 38,843.0 77,686 1

Nested Loop (cost=47,408.56..47,423.39 rows=2 width=96) (actual time=4,320.987..35,148.658 rows=77,686 loops=1)

11. 36.650 35,067.260 ↓ 38,843.0 77,686 1

Nested Loop (cost=47,408.42..47,423.01 rows=2 width=96) (actual time=4,320.981..35,067.260 rows=77,686 loops=1)

12. 481.038 34,952.924 ↓ 38,843.0 77,686 1

Nested Loop (cost=47,408.14..47,408.40 rows=2 width=92) (actual time=4,320.965..34,952.924 rows=77,686 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,726,834
13. 0.043 0.086 ↓ 8.0 8 1

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

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

Sort (cost=0.03..0.04 rows=1 width=29) (actual time=0.040..0.043 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.032 0.032 ↓ 8.0 8 1

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

16. 29,255.144 34,471.800 ↓ 181,391.2 725,565 8

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

17.          

CTE h

18. 1,399.469 1,877.166 ↓ 65,960.5 725,565 1

Hash Join (cost=104.80..47,407.11 rows=11 width=96) (actual time=19.621..1,877.166 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. 322.573 476.712 ↓ 998.9 824,102 1

Hash Join (cost=9.05..46,871.39 rows=825 width=100) (actual time=18.628..476.712 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. 154.032 154.032 ↑ 1.0 825,270 1

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

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

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

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

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

23. 0.439 0.985 ↓ 1.1 2,715 1

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

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

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

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

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

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

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

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

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

28. 0.036 2,855.853 ↓ 9.5 105 1

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

  • Buckets: 1,024 Batches: 1 Memory Usage: 13kB
29. 0.022 2,855.817 ↓ 9.5 105 1

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

30. 49.810 2,855.795 ↓ 9.5 105 1

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

31. 395.871 2,805.985 ↓ 65,960.5 725,565 1

Sort (cost=0.41..0.44 rows=11 width=16) (actual time=2,723.424..2,805.985 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,410.114 2,410.114 ↓ 65,960.5 725,565 1

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

33. 77.686 77.686 ↑ 1.0 1 77,686

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=77,686)

  • Index Cond: (id = h.sensor_id)
34. 77.686 77.686 ↑ 1.0 1 77,686

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=77,686)

  • Index Cond: (id = s.bru_id)
35. 77.686 77.686 ↑ 1.0 1 77,686

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=77,686)

  • Index Cond: (id = b.gateway_id)
36. 9.798 9.798 ↑ 1.0 6 9,798

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

37. 27.720 27.720 ↑ 1.0 1 630

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

Planning time : 2.793 ms
Execution time : 43,067.244 ms