explain.depesz.com

PostgreSQL's explain analyze made readable

Result: Kd3I : Optimization for: plan #DN4

Settings

Optimization path:

Optimization(s) for this plan:

# exclusive inclusive rows x rows loops node
1. 0.289 21,305.729 ↓ 119.0 119 1

WindowAgg (cost=14,070.97..14,071.05 rows=1 width=190) (actual time=21,305.464..21,305.729 rows=119 loops=1)

2.          

CTE weights_in_target

3. 49.386 11,514.143 ↓ 511.0 18,397 1

Nested Loop (cost=795.71..1,095.67 rows=36 width=12) (actual time=11,383.098..11,514.143 rows=18,397 loops=1)

4. 29.511 11,427.963 ↓ 511.0 18,397 1

Unique (cost=795.29..795.56 rows=36 width=20) (actual time=11,383.002..11,427.963 rows=18,397 loops=1)

5. 34.324 11,398.452 ↓ 514.3 18,514 1

Sort (cost=795.29..795.38 rows=36 width=20) (actual time=11,382.999..11,398.452 rows=18,514 loops=1)

  • Sort Key: d.date, d.person_id
  • Sort Method: quicksort Memory: 2215kB
6. 3,469.312 11,364.128 ↓ 514.3 18,514 1

HashAggregate (cost=705.28..794.36 rows=36 width=20) (actual time=11,275.792..11,364.128 rows=18,514 loops=1)

  • Group Key: d.date, d.person_id, c_1.id, s2.subcondition_count
  • Filter: (count(s.id) = s2.subcondition_count)
  • Rows Removed by Filter: 456810
7. 4,946.519 7,894.816 ↓ 465.3 3,315,812 1

Nested Loop (cost=40.93..616.21 rows=7,126 width=24) (actual time=0.297..7,894.816 rows=3,315,812 loops=1)

8. 0.092 0.457 ↓ 40.0 40 1

Nested Loop (cost=40.49..54.44 rows=1 width=28) (actual time=0.241..0.457 rows=40 loops=1)

9. 0.035 0.269 ↓ 4.0 4 1

Hash Join (cost=40.21..45.89 rows=1 width=16) (actual time=0.234..0.269 rows=4 loops=1)

  • Hash Cond: (c_1.id = s2.condition_id)
10. 0.041 0.041 ↑ 1.0 4 1

Seq Scan on condition c_1 (cost=0.00..5.66 rows=4 width=4) (actual time=0.019..0.041 rows=4 loops=1)

  • Filter: (target_id = 1)
  • Rows Removed by Filter: 289
11. 0.007 0.193 ↑ 1.0 4 1

Hash (cost=40.16..40.16 rows=4 width=12) (actual time=0.192..0.193 rows=4 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
12. 0.008 0.186 ↑ 1.0 4 1

Subquery Scan on s2 (cost=40.08..40.16 rows=4 width=12) (actual time=0.176..0.186 rows=4 loops=1)

13. 0.043 0.178 ↑ 1.0 4 1

HashAggregate (cost=40.08..40.12 rows=4 width=12) (actual time=0.174..0.178 rows=4 loops=1)

  • Group Key: c_2.id
14. 0.069 0.135 ↑ 1.0 40 1

Nested Loop (cost=0.28..39.88 rows=40 width=8) (actual time=0.018..0.135 rows=40 loops=1)

15. 0.022 0.022 ↑ 1.0 4 1

Seq Scan on condition c_2 (cost=0.00..5.66 rows=4 width=4) (actual time=0.007..0.022 rows=4 loops=1)

  • Filter: (target_id = 1)
  • Rows Removed by Filter: 289
16. 0.044 0.044 ↑ 1.0 10 4

Index Scan using subcondition_condition_id_idx on subcondition s_1 (cost=0.28..8.45 rows=10 width=8) (actual time=0.003..0.011 rows=10 loops=4)

  • Index Cond: (condition_id = c_2.id)
17. 0.096 0.096 ↑ 1.0 10 4

Index Scan using subcondition_condition_id_idx on subcondition s (cost=0.28..8.45 rows=10 width=20) (actual time=0.005..0.024 rows=10 loops=4)

  • Index Cond: (condition_id = c_1.id)
18. 2,947.840 2,947.840 ↓ 6.3 82,895 40

Index Scan using demography_demography_value_idx on demography d (cost=0.43..429.74 rows=13,203 width=16) (actual time=0.044..73.696 rows=82,895 loops=40)

  • Index Cond: ((demography = s.demography) AND (value >= s."from") AND (value <= s."to"))
19. 36.794 36.794 ↑ 1.0 1 18,397

Index Scan using weight_pkey on weight w (cost=0.42..8.33 rows=1 width=12) (actual time=0.002..0.002 rows=1 loops=18,397)

  • Index Cond: ((person_id = d.person_id) AND (date = d.date))
20. 0.253 21,305.440 ↓ 119.0 119 1

Sort (cost=12,975.30..12,975.30 rows=1 width=202) (actual time=21,305.351..21,305.440 rows=119 loops=1)

  • Sort Key: pro.id, ((e.value ->> 'date'::text)), ((e.value ->> 'channel'::text)), ((e.value ->> 'minute_from'::text)), ((e.value ->> 'minute_to'::text))
  • Sort Method: quicksort Memory: 86kB
21. 0.383 21,305.187 ↓ 119.0 119 1

GroupAggregate (cost=12,975.24..12,975.29 rows=1 width=202) (actual time=21,304.626..21,305.187 rows=119 loops=1)

  • Group Key: pro.id, (sum(p.weight)), c.minute, ((e.value ->> 'date'::text)), ((e.value ->> 'channel'::text)), ((e.value ->> 'minute_from'::text)), ((e.value ->> 'minute_to'::text))
22. 0.613 21,304.804 ↓ 261.0 261 1

Sort (cost=12,975.24..12,975.25 rows=1 width=198) (actual time=21,304.609..21,304.804 rows=261 loops=1)

  • Sort Key: pro.id, (sum(p.weight)), c.minute, ((e.value ->> 'date'::text)), ((e.value ->> 'channel'::text)), ((e.value ->> 'minute_from'::text)), ((e.value ->> 'minute_to'::text))
  • Sort Method: quicksort Memory: 159kB
23. 0.516 21,304.191 ↓ 261.0 261 1

Nested Loop (cost=8.93..12,975.23 rows=1 width=198) (actual time=21,277.396..21,304.191 rows=261 loops=1)

24. 107.379 107.379 ↓ 2.0 2 1

Seq Scan on programme pro (cost=0.00..2.50 rows=1 width=22) (actual time=107.371..107.379 rows=2 loops=1)

  • Filter: ((data ->> 'name'::text) = 'Gwiazdy Tańczą na Lodzie'::text)
  • Rows Removed by Filter: 100
25. 24.490 21,196.296 ↓ 130.0 130 2

Nested Loop (cost=8.93..12,972.71 rows=1 width=48) (actual time=10,585.004..10,598.148 rows=130 loops=2)

  • Join Filter: (c.date = p.date)
  • Rows Removed by Join Filter: 15530
26. 16.234 11,561.006 ↓ 3.3 120 2

HashAggregate (cost=0.90..1.26 rows=36 width=12) (actual time=5,780.376..5,780.503 rows=120 loops=2)

  • Group Key: p.date
27. 11,544.772 11,544.772 ↓ 511.0 18,397 1

CTE Scan on weights_in_target p (cost=0.00..0.72 rows=36 width=8) (actual time=11,383.102..11,544.772 rows=18,397 loops=1)

28. 24.076 9,610.800 ↓ 65.0 130 240

Materialize (cost=8.03..12,970.02 rows=2 width=48) (actual time=19.781..40.045 rows=130 loops=240)

29. 60.686 9,586.724 ↓ 65.0 130 2

Nested Loop (cost=8.03..12,970.01 rows=2 width=48) (actual time=2,373.648..4,793.362 rows=130 loops=2)

30. 33.186 33.186 ↓ 511.0 18,397 2

CTE Scan on weights_in_target per (cost=0.00..0.72 rows=36 width=12) (actual time=0.001..16.593 rows=18,397 loops=2)

31. 3,385.180 9,492.852 ↓ 0.0 0 36,794

Hash Join (cost=8.03..368.05 rows=1 width=44) (actual time=0.258..0.258 rows=0 loops=36,794)

  • Hash Cond: (((c.channel)::text = (e.value ->> 'channel'::text)) AND (c.date = ((e.value ->> 'date'::text))::date))
  • Join Filter: ((c.minute >= ((e.value ->> 'minute_from'::text))::integer) AND (c.minute <= ((e.value ->> 'minute_to'::text))::integer))
  • Rows Removed by Join Filter: 0
32. 5,666.122 6,107.638 ↓ 1.0 95 36,793

Bitmap Heap Scan on contact c (cost=5.52..364.23 rows=94 width=14) (actual time=0.021..0.166 rows=95 loops=36,793)

  • Recheck Cond: ((person_id = per.person_id) AND (date = per.date))
  • Heap Blocks: exact=3396414
33. 441.516 441.516 ↓ 1.0 95 36,793

Bitmap Index Scan on contact_pkey (cost=0.00..5.50 rows=94 width=0) (actual time=0.012..0.012 rows=95 loops=36,793)

  • Index Cond: ((person_id = per.person_id) AND (date = per.date))
34. 0.016 0.034 ↑ 100.0 1 2

Hash (cost=1.00..1.00 rows=100 width=32) (actual time=0.016..0.017 rows=1 loops=2)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
35. 0.018 0.018 ↑ 50.0 2 2

Function Scan on jsonb_array_elements e (cost=0.01..1.00 rows=100 width=32) (actual time=0.007..0.009 rows=2 loops=2)

Planning time : 1.412 ms
Execution time : 21,313.628 ms