explain.depesz.com

PostgreSQL's explain analyze made readable

Result: LHml

Settings
# exclusive inclusive rows x rows loops node
1. 11.479 41,133.145 ↑ 72,465.8 32 1

Hash Join (cost=784,190,735.72..887,405,176.10 rows=2,318,905 width=196) (actual time=41,124.028..41,133.145 rows=32 loops=1)

  • Hash Cond: ((st.run_id = lrid.run_id) AND (st.date = lrid.run_date))
2.          

CTE latest_run_id_dates

3. 0.034 107.639 ↑ 6.2 32 1

HashAggregate (cost=1,882,595.83..1,882,597.83 rows=200 width=8) (actual time=107.636..107.639 rows=32 loops=1)

  • Group Key: r_1.date
4. 0.404 107.605 ↑ 210.0 64 1

HashAggregate (cost=1,882,259.83..1,882,394.23 rows=13,440 width=86) (actual time=107.561..107.605 rows=64 loops=1)

  • Group Key: cm.level0top, rim_1.blueprint_id, rim_1.run_id, rim_1.backfill, rim_1.birthdate, r_1.date, rim_1.cancelled, m_1.valid_range, m_1.version, m_1.active_date_range, m_1.active
5. 2.380 107.201 ↑ 105.0 320 1

HashAggregate (cost=1,880,663.87..1,880,999.86 rows=33,599 width=118) (actual time=106.991..107.201 rows=320 loops=1)

  • Group Key: cm.level0top, rim_1.blueprint_id, rim_1.run_id, rim_1.backfill, rim_1.birthdate, r_1.date, rim_1.cancelled, s_1.stage, m_1.version, m_1.valid_range, m_1.active_date_range, m_1.active
6.          

CTE stages

7. 0.013 0.013 ↑ 20.0 5 1

Function Scan on unnest (cost=0.00..1.00 rows=100 width=32) (actual time=0.008..0.013 rows=5 loops=1)

8.          

CTE run_dates

9. 48.772 48.772 ↑ 1,180.8 51,849 1

Seq Scan on run_id_mapping (cost=0.00..307,493.35 rows=61,223,000 width=12) (actual time=0.043..48.772 rows=51,849 loops=1)

10. 2.314 104.821 ↑ 21.1 1,595 1

Nested Loop Left Join (cost=1,324.13..1,572,161.56 rows=33,599 width=118) (actual time=20.698..104.821 rows=1,595 loops=1)

  • Join Filter: (log_1.state = s_1.stage)
  • Rows Removed by Join Filter: 6380
11. 0.142 85.227 ↑ 105.0 320 1

Nested Loop (cost=1,323.58..1,533,472.70 rows=33,599 width=118) (actual time=19.142..85.227 rows=320 loops=1)

12. 0.015 0.015 ↑ 20.0 5 1

CTE Scan on stages s_1 (cost=0.00..2.00 rows=100 width=32) (actual time=0.009..0.015 rows=5 loops=1)

13. 0.105 85.070 ↑ 5.2 64 5

Materialize (cost=1,323.58..1,533,051.54 rows=336 width=86) (actual time=3.827..17.014 rows=64 loops=5)

14. 0.762 84.965 ↑ 5.2 64 1

Hash Join (cost=1,323.58..1,533,049.86 rows=336 width=86) (actual time=19.130..84.965 rows=64 loops=1)

  • Hash Cond: (r_1.run_id = rim_1.run_id)
15. 70.558 70.558 ↑ 99.1 3,090 1

CTE Scan on run_dates r_1 (cost=0.00..1,530,575.00 rows=306,115 width=8) (actual time=0.677..70.558 rows=3,090 loops=1)

  • Filter: ((date >= '2019-01-01'::date) AND (date <= '2019-02-01'::date))
  • Rows Removed by Filter: 48759
16. 0.066 13.645 ↓ 2.0 135 1

Hash (cost=1,322.74..1,322.74 rows=67 width=82) (actual time=13.645..13.645 rows=135 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 24kB
17. 0.054 13.579 ↓ 2.0 135 1

Nested Loop (cost=17.57..1,322.74 rows=67 width=82) (actual time=1.193..13.579 rows=135 loops=1)

18. 0.012 0.012 ↑ 1.0 1 1

Index Scan using master_idx on master m_1 (cost=0.14..2.16 rows=1 width=56) (actual time=0.011..0.012 rows=1 loops=1)

  • Index Cond: (level0top = 'VID_NESTLE_MASTER_1'::text)
19. 5.049 13.513 ↓ 2.0 135 1

Hash Join (cost=17.43..1,319.91 rows=67 width=47) (actual time=1.179..13.513 rows=135 loops=1)

  • Hash Cond: (rim_1.blueprint_id = cm.version)
20. 8.155 8.155 ↑ 2.1 29,195 1

Seq Scan on run_id_mapping rim_1 (cost=0.00..1,072.23 rows=61,223 width=25) (actual time=0.010..8.155 rows=29,195 loops=1)

21. 0.005 0.309 ↑ 3.5 4 1

Hash (cost=17.25..17.25 rows=14 width=30) (actual time=0.309..0.309 rows=4 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
22. 0.003 0.304 ↑ 3.5 4 1

Subquery Scan on cm (cost=17.08..17.25 rows=14 width=30) (actual time=0.301..0.304 rows=4 loops=1)

23. 0.014 0.301 ↑ 3.5 4 1

Sort (cost=17.08..17.11 rows=14 width=105) (actual time=0.301..0.301 rows=4 loops=1)

  • Sort Key: master_2.level0top, master_2.version DESC
  • Sort Method: quicksort Memory: 25kB
24. 0.004 0.287 ↑ 3.5 4 1

Append (cost=0.14..16.81 rows=14 width=105) (actual time=0.006..0.287 rows=4 loops=1)

25. 0.005 0.005 ↑ 1.0 1 1

Index Scan using master_idx on master master_2 (cost=0.14..2.16 rows=1 width=86) (actual time=0.005..0.005 rows=1 loops=1)

  • Index Cond: (level0top = 'VID_NESTLE_MASTER_1'::text)
26. 0.278 0.278 ↑ 4.3 3 1

Index Scan using master_version_history_idx on master master_3 (cost=0.29..14.51 rows=13 width=105) (actual time=0.274..0.278 rows=3 loops=1)

  • Index Cond: (level0top = 'VID_NESTLE_MASTER_1'::text)
27. 17.280 17.280 ↓ 25.0 25 320

Index Only Scan using run_log_pkey on run_log log_1 (cost=0.56..1.14 rows=1 width=14) (actual time=0.039..0.054 rows=25 loops=320)

  • Index Cond: ((date = r_1.date) AND (run_id = rim_1.run_id))
  • Heap Fetches: 0
28. 425.605 41,013.991 ↑ 15,583.5 29,761 1

GroupAggregate (cost=782,308,130.89..855,353,623.40 rows=463,780,905 width=160) (actual time=40,548.374..41,013.991 rows=29,761 loops=1)

  • Group Key: st.master_level0top, st.blueprint_id, st.run_id, st.backfill, st.birthdate, st.date, st.cancelled, st.latest_valid_range, st.latest_blueprint_id, st.latest_active_date_range, st.is_master_level0top_active
29. 282.260 40,588.386 ↑ 7,791.8 148,805 1

Sort (cost=782,308,130.89..785,206,761.55 rows=1,159,452,262 width=160) (actual time=40,548.300..40,588.386 rows=148,805 loops=1)

  • Sort Key: st.master_level0top, st.blueprint_id, st.run_id, st.backfill, st.birthdate, st.date, st.cancelled, st.latest_valid_range, st.latest_blueprint_id, st.latest_active_date_range, st.is_master_level0top_active
  • Sort Method: quicksort Memory: 61102kB
30. 57.645 40,306.126 ↑ 7,791.8 148,805 1

Subquery Scan on st (cost=471,602,917.64..555,663,206.63 rows=1,159,452,262 width=160) (actual time=37,162.058..40,306.126 rows=148,805 loops=1)

31. 2,586.749 40,248.481 ↑ 7,791.8 148,805 1

GroupAggregate (cost=471,602,917.64..544,068,684.01 rows=1,159,452,262 width=164) (actual time=37,162.053..40,248.481 rows=148,805 loops=1)

  • Group Key: master.level0top, rim.blueprint_id, rim.run_id, rim.backfill, rim.birthdate, r.date, rim.cancelled, s.stage, m.version, m.valid_range, m.active_date_range, m.active
32.          

CTE stages

33. 0.019 0.019 ↑ 20.0 5 1

Function Scan on unnest unnest_1 (cost=0.00..1.00 rows=100 width=32) (actual time=0.017..0.019 rows=5 loops=1)

34.          

CTE run_dates

35. 53.641 53.641 ↑ 1,180.8 51,849 1

Seq Scan on run_id_mapping run_id_mapping_1 (cost=0.00..307,493.35 rows=61,223,000 width=12) (actual time=0.051..53.641 rows=51,849 loops=1)

36. 13,283.570 37,661.732 ↑ 1,214.5 954,697 1

Sort (cost=471,295,423.29..474,194,053.94 rows=1,159,452,262 width=164) (actual time=37,161.949..37,661.732 rows=954,697 loops=1)

  • Sort Key: master.level0top, rim.blueprint_id, rim.run_id, rim.backfill, rim.birthdate, r.date, rim.cancelled, s.stage, m.version, m.valid_range, m.active_date_range, m.active
  • Sort Method: external merge Disk: 160432kB
37. 1,723.913 24,378.162 ↑ 1,214.5 954,697 1

Merge Left Join (cost=230,714,896.66..242,385,943.03 rows=1,159,452,262 width=164) (actual time=22,578.873..24,378.162 rows=954,697 loops=1)

  • Merge Cond: ((r.date = log.date) AND (rim.run_id = log.run_id) AND (s.stage = log.state))
38. 216.419 555.729 ↑ 7,788.1 148,875 1

Sort (cost=229,784,933.53..232,683,564.18 rows=1,159,452,262 width=118) (actual time=510.448..555.729 rows=148,875 loops=1)

  • Sort Key: r.date, rim.run_id, s.stage
  • Sort Method: quicksort Memory: 27198kB
39. 94.600 339.310 ↑ 7,788.1 148,875 1

Hash Right Join (cost=36,701.52..14,462,785.27 rows=1,159,452,262 width=118) (actual time=170.783..339.310 rows=148,875 loops=1)

  • Hash Cond: (r.run_id = rim.run_id)
40. 79.598 79.598 ↑ 1,180.8 51,849 1

CTE Scan on run_dates r (cost=0.00..1,224,460.00 rows=61,223,000 width=8) (actual time=0.053..79.598 rows=51,849 loops=1)

41. 42.866 165.112 ↑ 12.8 90,690 1

Hash (cost=22,208.37..22,208.37 rows=1,159,452 width=114) (actual time=165.112..165.112 rows=90,690 loops=1)

  • Buckets: 2097152 Batches: 1 Memory Usage: 27066kB
42. 35.386 122.246 ↑ 12.8 90,690 1

Nested Loop (cost=7,250.72..22,208.37 rows=1,159,452 width=114) (actual time=50.097..122.246 rows=90,690 loops=1)

43. 0.030 0.030 ↑ 20.0 5 1

CTE Scan on stages s (cost=0.00..2.00 rows=100 width=32) (actual time=0.020..0.030 rows=5 loops=1)

44. 20.912 86.830 ↓ 1.6 18,138 5

Materialize (cost=7,250.72..7,742.85 rows=11,594 width=82) (actual time=10.015..17.366 rows=18,138 loops=5)

45. 9.292 65.918 ↓ 1.6 18,138 1

Merge Join (cost=7,250.72..7,684.88 rows=11,594 width=82) (actual time=50.072..65.918 rows=18,138 loops=1)

  • Merge Cond: (master.version = rim.blueprint_id)
46. 3.795 32.701 ↓ 2.4 5,696 1

Sort (cost=1,310.71..1,316.75 rows=2,416 width=65) (actual time=31.498..32.701 rows=5,696 loops=1)

  • Sort Key: master.version
  • Sort Method: quicksort Memory: 994kB
47. 5.757 28.906 ↓ 2.4 5,696 1

Merge Join (cost=984.53..1,174.95 rows=2,416 width=65) (actual time=20.928..28.906 rows=5,696 loops=1)

  • Merge Cond: (master.level0top = m.level0top)
48. 17.985 22.063 ↑ 1.6 6,399 1

Sort (cost=979.75..1,005.45 rows=10,279 width=106) (actual time=20.836..22.063 rows=6,399 loops=1)

  • Sort Key: master.level0top, master.version DESC
  • Sort Method: quicksort Memory: 1464kB
49. 1.855 4.078 ↑ 1.6 6,399 1

Append (cost=0.00..294.79 rows=10,279 width=106) (actual time=0.010..4.078 rows=6,399 loops=1)

50. 0.024 0.024 ↑ 1.0 47 1

Seq Scan on master (cost=0.00..3.47 rows=47 width=87) (actual time=0.009..0.024 rows=47 loops=1)

51. 2.199 2.199 ↑ 1.6 6,352 1

Seq Scan on master master_1 (cost=0.00..291.32 rows=10,232 width=106) (actual time=0.006..2.199 rows=6,352 loops=1)

52. 1.069 1.086 ↓ 121.2 5,696 1

Sort (cost=4.78..4.89 rows=47 width=56) (actual time=0.087..1.086 rows=5,696 loops=1)

  • Sort Key: m.level0top
  • Sort Method: quicksort Memory: 31kB
53. 0.017 0.017 ↑ 1.0 47 1

Seq Scan on master m (cost=0.00..3.47 rows=47 width=56) (actual time=0.004..0.017 rows=47 loops=1)

54. 15.639 23.925 ↑ 2.5 24,224 1

Sort (cost=5,940.01..6,093.06 rows=61,223 width=25) (actual time=18.511..23.925 rows=24,224 loops=1)

  • Sort Key: rim.blueprint_id
  • Sort Method: quicksort Memory: 3049kB
55. 8.286 8.286 ↑ 2.1 29,195 1

Seq Scan on run_id_mapping rim (cost=0.00..1,072.23 rows=61,223 width=25) (actual time=0.033..8.286 rows=29,195 loops=1)

56. 1,732.916 22,098.520 ↑ 1.0 5,952,046 1

Materialize (cost=929,963.13..959,890.09 rows=5,985,393 width=60) (actual time=16,480.030..22,098.520 rows=5,952,046 loops=1)

57. 18,512.216 20,365.604 ↑ 1.0 5,940,402 1

Sort (cost=929,963.13..944,926.61 rows=5,985,393 width=60) (actual time=16,480.021..20,365.604 rows=5,940,402 loops=1)

  • Sort Key: log.date, log.run_id, log.state
  • Sort Method: external merge Disk: 392120kB
58. 1,853.388 1,853.388 ↑ 1.0 5,940,402 1

Seq Scan on run_log log (cost=0.00..127,622.93 rows=5,985,393 width=60) (actual time=0.007..1,853.388 rows=5,940,402 loops=1)

59. 0.012 107.675 ↑ 6.2 32 1

Hash (cost=4.00..4.00 rows=200 width=8) (actual time=107.675..107.675 rows=32 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 10kB
60. 107.663 107.663 ↑ 6.2 32 1

CTE Scan on latest_run_id_dates lrid (cost=0.00..4.00 rows=200 width=8) (actual time=107.638..107.663 rows=32 loops=1)

Planning time : 2.537 ms
Execution time : 41,234.461 ms