explain.depesz.com

PostgreSQL's explain analyze made readable

Result: jWn

Settings
# exclusive inclusive rows x rows loops node
1. 0.000 0.000 ↓ 0.0

Merge Left Join (cost=1,294,855.10..1,388,010.66 rows=79,356 width=164) (actual rows= loops=)

  • Merge Cond: ((items.project_id = ""*SELECT* 1"".project_id) AND ((COALESCE(pa.activity_id, items.activity_id, staff_membership_activity_links.activity_id)) = ""*SELECT* 1"".activity_id))
  • Join Filter: ((items.date >= "*SELECT* 1".start_date) AND ((items.date <= "*SELECT* 1".end_date) OR ("*SELECT* 1".end_date IS NULL)))
2. 0.000 0.000 ↓ 0.0

Sort (cost=1,247,913.83..1,248,112.22 rows=79,356 width=644) (actual rows= loops=)

  • Sort Key: items.project_id, (COALESCE(pa.activity_id, items.activity_id, staff_membership_activity_links.activity_id))
3. 0.000 0.000 ↓ 0.0

Hash Join (cost=779,975.16..1,241,455.81 rows=79,356 width=644) (actual rows= loops=)

  • Hash Cond: (items.account_id = accounts.id)
4. 0.000 0.000 ↓ 0.0

Append (cost=779,956.49..1,238,424.06 rows=238,067 width=644) (actual rows= loops=)

5. 0.000 0.000 ↓ 0.0

Merge Left Join (cost=779,956.49..980,030.15 rows=238,066 width=103) (actual rows= loops=)

  • Merge Cond: (items.project_plan_id = pa.project_plan_id)
  • Join Filter: ((items.date >= pa.start_date) AND (items.date <= pa.end_date) AND ((pa.plan_row_uuid = items.plan_row_uuid) OR (items.plan_row_uuid IS NULL)) AND ((pa.user_id = items.user_id) OR (items.user_id IS NULL)) AND ((pa.epic_id = items.epic_id) OR ((items.reportable_type = 'PlanItem'::text) AND (items.epic_id IS NULL)) OR ((items.reportable_type = 'TimeLog'::text) AND (pa.epic_id IS NULL))))
6. 0.000 0.000 ↓ 0.0

Sort (cost=770,889.61..771,484.77 rows=238,066 width=144) (actual rows= loops=)

  • Sort Key: items.project_plan_id
7. 0.000 0.000 ↓ 0.0

Merge Left Join (cost=742,175.06..749,629.12 rows=238,066 width=144) (actual rows= loops=)

  • Merge Cond: ((items.account_id = staff_memberships.account_id) AND (items.user_id = staff_memberships.user_id))
  • Join Filter: ((items.date >= (COALESCE(staff_membership_activity_links.start_date, staff_memberships.joined_at))) AND (items.date <= (COALESCE(lag((staff_membership_activity_links.start_date - 1), 1) OVER (?), staff_memberships.archived_at, '3000-01-01'::date))))
  • Filter: ((items.vacation_hours IS NULL) OR (items.vacation_hours < (COALESCE(staff_membership_activity_links.capacity, '8'::numeric))::double precision))
8. 0.000 0.000 ↓ 0.0

Sort (cost=741,327.92..743,095.73 rows=707,126 width=120) (actual rows= loops=)

  • Sort Key: items.account_id, items.user_id
9. 0.000 0.000 ↓ 0.0

Subquery Scan on items (cost=588,648.59..672,624.94 rows=707,126 width=120) (actual rows= loops=)

10. 0.000 0.000 ↓ 0.0

Append (cost=588,648.59..665,553.68 rows=707,126 width=124) (actual rows= loops=)

11.          

CTE items

12. 0.000 0.000 ↓ 0.0

Nested Loop (cost=2,125.79..504,914.10 rows=657,101 width=110) (actual rows= loops=)

13. 0.000 0.000 ↓ 0.0

Hash Join (cost=2,125.78..3,875.34 rows=26,284 width=74) (actual rows= loops=)

  • Hash Cond: (projects_5.client_id = clients_3.id)
14. 0.000 0.000 ↓ 0.0

Hash Join (cost=2,062.18..3,742.59 rows=26,284 width=70) (actual rows= loops=)

  • Hash Cond: (project_plans.project_id = projects_5.id)
15. 0.000 0.000 ↓ 0.0

Hash Join (cost=1,833.41..3,444.77 rows=26,284 width=62) (actual rows= loops=)

  • Hash Cond: (plan_items.plan_row_uuid = plan_rows_1.uuid)
16. 0.000 0.000 ↓ 0.0

Hash Join (cost=202.03..1,744.37 rows=26,284 width=50) (actual rows= loops=)

  • Hash Cond: (plan_items.project_plan_id = project_plans.id)
17. 0.000 0.000 ↓ 0.0

Seq Scan on plan_items (cost=0.00..1,396.10 rows=55,675 width=46) (actual rows= loops=)

  • Filter: (utilization > '0'::numeric)
18. 0.000 0.000 ↓ 0.0

Hash (cost=166.39..166.39 rows=2,851 width=8) (actual rows= loops=)

19. 0.000 0.000 ↓ 0.0

Seq Scan on project_plans (cost=0.00..166.39 rows=2,851 width=8) (actual rows= loops=)

  • Filter: active
20. 0.000 0.000 ↓ 0.0

Hash (cost=1,030.06..1,030.06 rows=48,106 width=28) (actual rows= loops=)

21. 0.000 0.000 ↓ 0.0

Seq Scan on plan_rows plan_rows_1 (cost=0.00..1,030.06 rows=48,106 width=28) (actual rows= loops=)

22. 0.000 0.000 ↓ 0.0

Hash (cost=156.12..156.12 rows=5,812 width=12) (actual rows= loops=)

23. 0.000 0.000 ↓ 0.0

Seq Scan on projects projects_5 (cost=0.00..156.12 rows=5,812 width=12) (actual rows= loops=)

24. 0.000 0.000 ↓ 0.0

Hash (cost=40.49..40.49 rows=1,849 width=8) (actual rows= loops=)

25. 0.000 0.000 ↓ 0.0

Seq Scan on clients clients_3 (cost=0.00..40.49 rows=1,849 width=8) (actual rows= loops=)

26. 0.000 0.000 ↓ 0.0

Function Scan on generate_series generate_series_1 (cost=0.01..18.76 rows=25 width=8) (actual rows= loops=)

  • Filter: (date_part('dow'::text, generate_series) = ANY ('{1,2,3,4,5}'::double precision[]))
27. 0.000 0.000 ↓ 0.0

Subquery Scan on *SELECT* 1_1 (cost=83,734.49..118,549.01 rows=3,286 width=124) (actual rows= loops=)

28. 0.000 0.000 ↓ 0.0

Hash Left Join (cost=83,734.49..118,491.50 rows=3,286 width=141) (actual rows= loops=)

  • Hash Cond: ((items_1.account_id = summary_vacations_by_dates.account_id) AND (items_1.date = summary_vacations_by_dates.date) AND (items_1.user_id = summary_vacations_by_dates.user_id))
  • Join Filter: (items_1.user_id IS NOT NULL)
29. 0.000 0.000 ↓ 0.0

Merge Left Join (cost=82,655.17..115,169.48 rows=3,286 width=128) (actual rows= loops=)

  • Merge Cond: ((items_1.account_id = nw_intervals_by_dates_roles.account_id) AND (items_1.date = nw_intervals_by_dates_roles.date))
  • Join Filter: ((items_1.user_id IS NULL) AND (nw_intervals_by_dates_roles.office_id = items_1.office_id))
  • Filter: (COALESCE(non_working_intervals_by_dates.id, nw_intervals_by_dates_roles.id) IS NULL)
30. 0.000 0.000 ↓ 0.0

Merge Left Join (cost=82,654.88..89,830.45 rows=657,101 width=128) (actual rows= loops=)

  • Merge Cond: ((items_1.account_id = non_working_intervals_by_dates.account_id) AND (items_1.date = non_working_intervals_by_dates.date) AND (items_1.user_id = non_working_intervals_by_dates.user_id))
  • Join Filter: (items_1.user_id IS NOT NULL)
31. 0.000 0.000 ↓ 0.0

Sort (cost=76,636.89..78,279.64 rows=657,101 width=124) (actual rows= loops=)

  • Sort Key: items_1.account_id, items_1.date, items_1.user_id
32. 0.000 0.000 ↓ 0.0

CTE Scan on items items_1 (cost=0.00..13,142.02 rows=657,101 width=124) (actual rows= loops=)

33. 0.000 0.000 ↓ 0.0

Sort (cost=6,017.99..6,167.27 rows=59,712 width=16) (actual rows= loops=)

  • Sort Key: non_working_intervals_by_dates.account_id, non_working_intervals_by_dates.date, non_working_intervals_by_dates.user_id
34. 0.000 0.000 ↓ 0.0

Seq Scan on non_working_intervals_by_dates (cost=0.00..1,281.12 rows=59,712 width=16) (actual rows= loops=)

35. 0.000 0.000 ↓ 0.0

Materialize (cost=0.29..3,349.01 rows=59,712 width=16) (actual rows= loops=)

36. 0.000 0.000 ↓ 0.0

Index Scan using nw_account_id_date on non_working_intervals_by_dates nw_intervals_by_dates_roles (cost=0.29..3,199.73 rows=59,712 width=16) (actual rows= loops=)

37. 0.000 0.000 ↓ 0.0

Hash (cost=514.66..514.66 rows=32,266 width=17) (actual rows= loops=)

38. 0.000 0.000 ↓ 0.0

Seq Scan on summary_vacations_by_dates_m summary_vacations_by_dates (cost=0.00..514.66 rows=32,266 width=17) (actual rows= loops=)

39. 0.000 0.000 ↓ 0.0

Hash Join (cost=2,124.60..31,516.54 rows=703,840 width=124) (actual rows= loops=)

  • Hash Cond: (time_logs.epic_id = epics.id)
40. 0.000 0.000 ↓ 0.0

Seq Scan on time_logs (cost=0.00..16,194.61 rows=703,961 width=28) (actual rows= loops=)

41. 0.000 0.000 ↓ 0.0

Hash (cost=1,794.22..1,794.22 rows=26,430 width=20) (actual rows= loops=)

42. 0.000 0.000 ↓ 0.0

Hash Left Join (cost=430.80..1,794.22 rows=26,430 width=20) (actual rows= loops=)

  • Hash Cond: (epics.project_id = general_epic_plans.project_id)
  • Join Filter: (epics.project_plan_id IS NULL)
43. 0.000 0.000 ↓ 0.0

Hash Join (cost=228.77..917.57 rows=26,430 width=16) (actual rows= loops=)

  • Hash Cond: (epics.project_id = projects.id)
44. 0.000 0.000 ↓ 0.0

Seq Scan on epics (cost=0.00..619.35 rows=26,435 width=12) (actual rows= loops=)

45. 0.000 0.000 ↓ 0.0

Hash (cost=156.12..156.12 rows=5,812 width=8) (actual rows= loops=)

46. 0.000 0.000 ↓ 0.0

Seq Scan on projects (cost=0.00..156.12 rows=5,812 width=8) (actual rows= loops=)

47. 0.000 0.000 ↓ 0.0

Hash (cost=166.39..166.39 rows=2,851 width=8) (actual rows= loops=)

48. 0.000 0.000 ↓ 0.0

Seq Scan on project_plans general_epic_plans (cost=0.00..166.39 rows=2,851 width=8) (actual rows= loops=)

  • Filter: active
49. 0.000 0.000 ↓ 0.0

Materialize (cost=847.14..942.74 rows=4,249 width=40) (actual rows= loops=)

50. 0.000 0.000 ↓ 0.0

Unique (cost=847.14..889.63 rows=4,249 width=65) (actual rows= loops=)

51. 0.000 0.000 ↓ 0.0

Sort (cost=847.14..857.76 rows=4,249 width=65) (actual rows= loops=)

  • Sort Key: staff_memberships.account_id, staff_memberships.user_id, (COALESCE(staff_membership_activity_links.start_date, staff_memberships.joined_at)), (COALESCE(lag((staff_membership_activity_links.start_date - 1), 1) OVER (?), staff_memberships.archived_at, '3000-01-01'::date)) DESC
52. 0.000 0.000 ↓ 0.0

WindowAgg (cost=484.85..591.08 rows=4,249 width=65) (actual rows= loops=)

53. 0.000 0.000 ↓ 0.0

Sort (cost=484.85..495.47 rows=4,249 width=56) (actual rows= loops=)

  • Sort Key: staff_membership_activity_links.staff_membership_id, staff_membership_activity_links.start_date DESC NULLS LAST
54. 0.000 0.000 ↓ 0.0

Hash Join (cost=138.05..228.79 rows=4,249 width=56) (actual rows= loops=)

  • Hash Cond: (staff_membership_activity_links.staff_membership_id = staff_memberships.id)
55. 0.000 0.000 ↓ 0.0

Seq Scan on staff_membership_activity_links (cost=0.00..79.56 rows=4,256 width=28) (actual rows= loops=)

56. 0.000 0.000 ↓ 0.0

Hash (cost=88.02..88.02 rows=4,002 width=32) (actual rows= loops=)

57. 0.000 0.000 ↓ 0.0

Seq Scan on staff_memberships (cost=0.00..88.02 rows=4,002 width=32) (actual rows= loops=)

58. 0.000 0.000 ↓ 0.0

Sort (cost=9,066.88..9,079.24 rows=4,941 width=48) (actual rows= loops=)

  • Sort Key: pa.project_plan_id
59. 0.000 0.000 ↓ 0.0

Subquery Scan on pa (cost=8,640.22..8,763.74 rows=4,941 width=48) (actual rows= loops=)

60. 0.000 0.000 ↓ 0.0

HashAggregate (cost=8,640.22..8,714.33 rows=4,941 width=48) (actual rows= loops=)

  • Group Key: plan_rows.project_plan_id, plan_rows.epic_id, plan_rows.user_id, plan_roles.activity_id, COALESCE(plan_roles.start_date, '1980-01-01'::date), COALESCE(lag((plan_roles.start_date - 1), 1) OVER (?), '3000-01-01'::date)
61. 0.000 0.000 ↓ 0.0

WindowAgg (cost=6,076.81..7,079.88 rows=44,581 width=68) (actual rows= loops=)

62. 0.000 0.000 ↓ 0.0

Sort (cost=6,076.81..6,188.26 rows=44,581 width=60) (actual rows= loops=)

  • Sort Key: plan_roles.plan_row_uuid, plan_roles.start_date DESC NULLS LAST
63. 0.000 0.000 ↓ 0.0

Hash Join (cost=1,631.38..2,634.23 rows=44,581 width=60) (actual rows= loops=)

  • Hash Cond: (plan_roles.plan_row_uuid = plan_rows.uuid)
64. 0.000 0.000 ↓ 0.0

Seq Scan on plan_roles (cost=0.00..885.81 rows=44,581 width=32) (actual rows= loops=)

65. 0.000 0.000 ↓ 0.0

Hash (cost=1,030.06..1,030.06 rows=48,106 width=28) (actual rows= loops=)

66. 0.000 0.000 ↓ 0.0

Seq Scan on plan_rows (cost=0.00..1,030.06 rows=48,106 width=28) (actual rows= loops=)

67. 0.000 0.000 ↓ 0.0

Subquery Scan on *SELECT* 2_1 (cost=247,975.87..254,822.92 rows=1 width=103) (actual rows= loops=)

68. 0.000 0.000 ↓ 0.0

Merge Right Join (cost=247,975.87..254,822.90 rows=1 width=110) (actual rows= loops=)

  • Merge Cond: ((non_working_intervals_by_dates_1.account_id = staff_memberships_1.account_id) AND (non_working_intervals_by_dates_1.date = generate_series.generate_series) AND (non_working_intervals_by_dates_1.user_id = staff_memberships_1.user_id))
  • Filter: (non_working_intervals_by_dates_1.id IS NULL)
69. 0.000 0.000 ↓ 0.0

Index Scan using account_id_user_id on non_working_intervals_by_dates non_working_intervals_by_dates_1 (cost=0.41..3,467.85 rows=59,712 width=16) (actual rows= loops=)

70. 0.000 0.000 ↓ 0.0

Sort (cost=247,975.46..248,698.42 rows=289,183 width=64) (actual rows= loops=)

  • Sort Key: staff_memberships_1.account_id, generate_series.generate_series, staff_memberships_1.user_id
71. 0.000 0.000 ↓ 0.0

Nested Loop (cost=1,253.91..221,744.21 rows=289,183 width=64) (actual rows= loops=)

72. 0.000 0.000 ↓ 0.0

Hash Join (cost=1,253.91..1,952.21 rows=11,568 width=64) (actual rows= loops=)

  • Hash Cond: (vacations.staff_membership_id = staff_memberships_1.id)
73. 0.000 0.000 ↓ 0.0

Seq Scan on vacations (cost=0.00..500.92 rows=21,792 width=44) (actual rows= loops=)

74. 0.000 0.000 ↓ 0.0

Hash (cost=1,227.36..1,227.36 rows=2,124 width=32) (actual rows= loops=)

75. 0.000 0.000 ↓ 0.0

Hash Join (cost=1,107.35..1,227.36 rows=2,124 width=32) (actual rows= loops=)

  • Hash Cond: (staff_membership_activity_links_1.staff_membership_id = staff_memberships_1.id)
76. 0.000 0.000 ↓ 0.0

Hash Join (cost=969.31..1,083.71 rows=2,128 width=16) (actual rows= loops=)

  • Hash Cond: (staff_membership_activity_links_1.id = staff_activities_with_dates.link_id)
77. 0.000 0.000 ↓ 0.0

Seq Scan on staff_membership_activity_links staff_membership_activity_links_1 (cost=0.00..79.56 rows=4,256 width=20) (actual rows= loops=)

78. 0.000 0.000 ↓ 0.0

Hash (cost=967.01..967.01 rows=184 width=4) (actual rows= loops=)

79. 0.000 0.000 ↓ 0.0

HashAggregate (cost=965.17..967.01 rows=184 width=4) (actual rows= loops=)

  • Group Key: staff_activities_with_dates.link_id
80. 0.000 0.000 ↓ 0.0

Subquery Scan on staff_activities_with_dates (cost=836.52..963.99 rows=472 width=4) (actual rows= loops=)

  • Filter: ((CURRENT_DATE >= staff_activities_with_dates.start_date) AND (CURRENT_DATE <= staff_activities_with_dates.end_date))
81. 0.000 0.000 ↓ 0.0

Unique (cost=836.52..879.01 rows=4,249 width=613) (actual rows= loops=)

82. 0.000 0.000 ↓ 0.0

Sort (cost=836.52..847.14 rows=4,249 width=613) (actual rows= loops=)

  • Sort Key: staff_memberships_2.account_id, staff_memberships_2.user_id, (COALESCE(staff_membership_activity_links_2.start_date, staff_memberships_2.joined_at)), (COALESCE(lag((staff_membership_activity_links_2.start_date - 1), 1) OVER (?), staff_memberships_2.archived_at, '3000-01-01'::date)) DESC
83. 0.000 0.000 ↓ 0.0

WindowAgg (cost=484.85..580.45 rows=4,249 width=613) (actual rows= loops=)

84. 0.000 0.000 ↓ 0.0

Sort (cost=484.85..495.47 rows=4,249 width=28) (actual rows= loops=)

  • Sort Key: staff_membership_activity_links_2.staff_membership_id, staff_membership_activity_links_2.start_date DESC NULLS LAST
85. 0.000 0.000 ↓ 0.0

Hash Join (cost=138.05..228.79 rows=4,249 width=28) (actual rows= loops=)

  • Hash Cond: (staff_membership_activity_links_2.staff_membership_id = staff_memberships_2.id)
86. 0.000 0.000 ↓ 0.0

Seq Scan on staff_membership_activity_links staff_membership_activity_links_2 (cost=0.00..79.56 rows=4,256 width=12) (actual rows= loops=)

87. 0.000 0.000 ↓ 0.0

Hash (cost=88.02..88.02 rows=4,002 width=20) (actual rows= loops=)

88. 0.000 0.000 ↓ 0.0

Seq Scan on staff_memberships staff_memberships_2 (cost=0.00..88.02 rows=4,002 width=20) (actual rows= loops=)

89. 0.000 0.000 ↓ 0.0

Hash (cost=88.02..88.02 rows=4,002 width=16) (actual rows= loops=)

90. 0.000 0.000 ↓ 0.0

Seq Scan on staff_memberships staff_memberships_1 (cost=0.00..88.02 rows=4,002 width=16) (actual rows= loops=)

91. 0.000 0.000 ↓ 0.0

Function Scan on generate_series (cost=0.01..18.76 rows=25 width=8) (actual rows= loops=)

  • Filter: (date_part('dow'::text, generate_series) = ANY ('{1,2,3,4,5}'::double precision[]))
92. 0.000 0.000 ↓ 0.0

Hash (cost=17.20..17.20 rows=118 width=4) (actual rows= loops=)

93. 0.000 0.000 ↓ 0.0

Seq Scan on accounts (cost=0.00..17.20 rows=118 width=4) (actual rows= loops=)

  • Filter: ((suspended_at)::date >= CURRENT_DATE)
94. 0.000 0.000 ↓ 0.0

Sort (cost=46,941.27..47,625.25 rows=273,590 width=44) (actual rows= loops=)

  • Sort Key: ""*SELECT* 1"".project_id, ""*SELECT* 1"".activity_id
95. 0.000 0.000 ↓ 0.0

Append (cost=294.94..22,233.83 rows=273,590 width=44) (actual rows= loops=)

96. 0.000 0.000 ↓ 0.0

Subquery Scan on *SELECT* 1 (cost=294.94..474.15 rows=49 width=44) (actual rows= loops=)

97. 0.000 0.000 ↓ 0.0

Merge Join (cost=294.94..473.66 rows=49 width=612) (actual rows= loops=)

  • Merge Cond: (clients.brand_id = brands.id)
98. 0.000 0.000 ↓ 0.0

Nested Loop (cost=294.80..1,672.00 rows=49 width=52) (actual rows= loops=)

99. 0.000 0.000 ↓ 0.0

Merge Join (cost=294.38..294.67 rows=1 width=32) (actual rows= loops=)

  • Merge Cond: (rate_cards.rateable_id = clients.brand_id)
100. 0.000 0.000 ↓ 0.0

WindowAgg (cost=108.61..111.49 rows=115 width=45) (actual rows= loops=)

101. 0.000 0.000 ↓ 0.0

Sort (cost=108.61..108.90 rows=115 width=29) (actual rows= loops=)

  • Sort Key: rate_cards.rateable_id, rate_cards.start_date DESC NULLS LAST
102. 0.000 0.000 ↓ 0.0

Seq Scan on rate_cards (cost=0.00..104.68 rows=115 width=29) (actual rows= loops=)

  • Filter: ((rateable_type)::text = 'Brand'::text)
103. 0.000 0.000 ↓ 0.0

Sort (cost=185.76..185.78 rows=5 width=8) (actual rows= loops=)

  • Sort Key: clients.brand_id
104. 0.000 0.000 ↓ 0.0

Nested Loop (cost=0.56..185.71 rows=5 width=8) (actual rows= loops=)

105. 0.000 0.000 ↓ 0.0

Nested Loop (cost=0.28..184.13 rows=5 width=8) (actual rows= loops=)

106. 0.000 0.000 ↓ 0.0

Seq Scan on pricing_models (cost=0.00..142.62 rows=5 width=4) (actual rows= loops=)

  • Filter: ((rates_type)::text = 'brand'::text)
107. 0.000 0.000 ↓ 0.0

Index Scan using projects_pkey on projects projects_1 (cost=0.28..8.30 rows=1 width=8) (actual rows= loops=)

  • Index Cond: (id = pricing_models.project_id)
108. 0.000 0.000 ↓ 0.0

Index Scan using clients_pkey on clients (cost=0.28..0.32 rows=1 width=8) (actual rows= loops=)

  • Index Cond: (id = projects_1.client_id)
109. 0.000 0.000 ↓ 0.0

Index Scan using index_rates_on_activity_id_and_rate_card_id on rates (cost=0.42..1,376.84 rows=49 width=28) (actual rows= loops=)

  • Index Cond: (rate_card_id = rate_cards.id)
110. 0.000 0.000 ↓ 0.0

Index Only Scan using brands_pkey on brands (cost=0.14..9.87 rows=115 width=4) (actual rows= loops=)

111. 0.000 0.000 ↓ 0.0

Subquery Scan on *SELECT* 2 (cost=583.65..5,487.33 rows=35,359 width=44) (actual rows= loops=)

112. 0.000 0.000 ↓ 0.0

Hash Join (cost=583.65..5,133.74 rows=35,359 width=612) (actual rows= loops=)

  • Hash Cond: (rates_1.rate_card_id = rate_cards_with_dates.id)
113. 0.000 0.000 ↓ 0.0

Seq Scan on rates rates_1 (cost=0.00..3,542.37 rows=174,437 width=28) (actual rows= loops=)

114. 0.000 0.000 ↓ 0.0

Hash (cost=574.65..574.65 rows=720 width=24) (actual rows= loops=)

115. 0.000 0.000 ↓ 0.0

Hash Join (cost=377.68..574.65 rows=720 width=24) (actual rows= loops=)

  • Hash Cond: (clients_1.office_id = rate_cards_with_dates.rateable_id)
116. 0.000 0.000 ↓ 0.0

Hash Join (cost=227.94..415.36 rows=623 width=12) (actual rows= loops=)

  • Hash Cond: (clients_1.office_id = offices.id)
117. 0.000 0.000 ↓ 0.0

Hash Join (cost=214.02..399.80 rows=623 width=8) (actual rows= loops=)

  • Hash Cond: (projects_2.client_id = clients_1.id)
118. 0.000 0.000 ↓ 0.0

Hash Join (cost=150.41..334.56 rows=623 width=8) (actual rows= loops=)

  • Hash Cond: (projects_2.id = pricing_models_1.project_id)
119. 0.000 0.000 ↓ 0.0

Seq Scan on projects projects_2 (cost=0.00..156.12 rows=5,812 width=8) (actual rows= loops=)

120. 0.000 0.000 ↓ 0.0

Hash (cost=142.62..142.62 rows=623 width=4) (actual rows= loops=)

121. 0.000 0.000 ↓ 0.0

Seq Scan on pricing_models pricing_models_1 (cost=0.00..142.62 rows=623 width=4) (actual rows= loops=)

  • Filter: ((rates_type)::text = 'office'::text)
122. 0.000 0.000 ↓ 0.0

Hash (cost=40.49..40.49 rows=1,849 width=8) (actual rows= loops=)

123. 0.000 0.000 ↓ 0.0

Seq Scan on clients clients_1 (cost=0.00..40.49 rows=1,849 width=8) (actual rows= loops=)

124. 0.000 0.000 ↓ 0.0

Hash (cost=8.41..8.41 rows=441 width=4) (actual rows= loops=)

125. 0.000 0.000 ↓ 0.0

Seq Scan on offices (cost=0.00..8.41 rows=441 width=4) (actual rows= loops=)

126. 0.000 0.000 ↓ 0.0

Hash (cost=143.63..143.63 rows=489 width=24) (actual rows= loops=)

127. 0.000 0.000 ↓ 0.0

Subquery Scan on rate_cards_with_dates (cost=126.52..143.63 rows=489 width=24) (actual rows= loops=)

128. 0.000 0.000 ↓ 0.0

WindowAgg (cost=126.52..138.74 rows=489 width=45) (actual rows= loops=)

129. 0.000 0.000 ↓ 0.0

Sort (cost=126.52..127.74 rows=489 width=29) (actual rows= loops=)

  • Sort Key: rate_cards_1.rateable_id, rate_cards_1.start_date DESC NULLS LAST
130. 0.000 0.000 ↓ 0.0

Seq Scan on rate_cards rate_cards_1 (cost=0.00..104.68 rows=489 width=29) (actual rows= loops=)

  • Filter: ((rateable_type)::text = 'Office'::text)
131. 0.000 0.000 ↓ 0.0

Subquery Scan on *SELECT* 3 (cost=834.13..9,370.95 rows=206,113 width=44) (actual rows= loops=)

132. 0.000 0.000 ↓ 0.0

Hash Join (cost=834.13..7,309.82 rows=206,113 width=612) (actual rows= loops=)

  • Hash Cond: (rates_2.rate_card_id = rate_cards_2.id)
133. 0.000 0.000 ↓ 0.0

Seq Scan on rates rates_2 (cost=0.00..3,542.37 rows=174,437 width=28) (actual rows= loops=)

134. 0.000 0.000 ↓ 0.0

Hash (cost=781.67..781.67 rows=4,197 width=24) (actual rows= loops=)

135. 0.000 0.000 ↓ 0.0

Hash Join (cost=580.30..781.67 rows=4,197 width=24) (actual rows= loops=)

  • Hash Cond: (projects_3.client_id = clients_2.id)
136. 0.000 0.000 ↓ 0.0

Hash Join (cost=228.77..380.91 rows=3,620 width=8) (actual rows= loops=)

  • Hash Cond: (pricing_models_2.project_id = projects_3.id)
137. 0.000 0.000 ↓ 0.0

Seq Scan on pricing_models pricing_models_2 (cost=0.00..142.62 rows=3,621 width=4) (actual rows= loops=)

  • Filter: ((rates_type)::text = 'client'::text)
138. 0.000 0.000 ↓ 0.0

Hash (cost=156.12..156.12 rows=5,812 width=8) (actual rows= loops=)

139. 0.000 0.000 ↓ 0.0

Seq Scan on projects projects_3 (cost=0.00..156.12 rows=5,812 width=8) (actual rows= loops=)

140. 0.000 0.000 ↓ 0.0

Hash (cost=328.77..328.77 rows=1,821 width=28) (actual rows= loops=)

141. 0.000 0.000 ↓ 0.0

Merge Join (cost=203.56..328.77 rows=1,821 width=28) (actual rows= loops=)

  • Merge Cond: (rate_cards_2.rateable_id = clients_2.id)
142. 0.000 0.000 ↓ 0.0

WindowAgg (cost=203.29..248.81 rows=1,821 width=45) (actual rows= loops=)

143. 0.000 0.000 ↓ 0.0

Sort (cost=203.29..207.84 rows=1,821 width=29) (actual rows= loops=)

  • Sort Key: rate_cards_2.rateable_id, rate_cards_2.start_date DESC NULLS LAST
144. 0.000 0.000 ↓ 0.0

Seq Scan on rate_cards rate_cards_2 (cost=0.00..104.68 rows=1,821 width=29) (actual rows= loops=)

  • Filter: ((rateable_type)::text = 'Client'::text)
145. 0.000 0.000 ↓ 0.0

Index Only Scan using clients_pkey on clients clients_2 (cost=0.28..60.01 rows=1,849 width=4) (actual rows= loops=)

146. 0.000 0.000 ↓ 0.0

Subquery Scan on *SELECT* 4 (cost=695.56..5,533.45 rows=32,069 width=44) (actual rows= loops=)

147. 0.000 0.000 ↓ 0.0

Hash Join (cost=695.56..5,212.76 rows=32,069 width=612) (actual rows= loops=)

  • Hash Cond: (rates_3.rate_card_id = rate_cards_3.id)
148. 0.000 0.000 ↓ 0.0

Seq Scan on rates rates_3 (cost=0.00..3,542.37 rows=174,437 width=28) (actual rows= loops=)

149. 0.000 0.000 ↓ 0.0

Hash (cost=687.40..687.40 rows=653 width=24) (actual rows= loops=)

150. 0.000 0.000 ↓ 0.0

Hash Join (cost=502.95..687.40 rows=653 width=24) (actual rows= loops=)

  • Hash Cond: (projects_4.id = pricing_models_3.project_id)
151. 0.000 0.000 ↓ 0.0

Seq Scan on projects projects_4 (cost=0.00..156.12 rows=5,812 width=4) (actual rows= loops=)

152. 0.000 0.000 ↓ 0.0

Hash (cost=494.79..494.79 rows=653 width=24) (actual rows= loops=)

153. 0.000 0.000 ↓ 0.0

Hash Join (cost=403.40..494.79 rows=653 width=24) (actual rows= loops=)

  • Hash Cond: (rate_cards_3.rateable_id = pricing_models_3.id)
154. 0.000 0.000 ↓ 0.0

WindowAgg (cost=241.26..301.98 rows=2,429 width=45) (actual rows= loops=)

155. 0.000 0.000 ↓ 0.0

Sort (cost=241.26..247.33 rows=2,429 width=29) (actual rows= loops=)

  • Sort Key: rate_cards_3.rateable_id, rate_cards_3.start_date DESC NULLS LAST
156. 0.000 0.000 ↓ 0.0

Seq Scan on rate_cards rate_cards_3 (cost=0.00..104.68 rows=2,429 width=29) (actual rows= loops=)

  • Filter: ((rateable_type)::text = 'PricingModel'::text)
157. 0.000 0.000 ↓ 0.0

Hash (cost=142.62..142.62 rows=1,561 width=8) (actual rows= loops=)

158. 0.000 0.000 ↓ 0.0

Seq Scan on pricing_models pricing_models_3 (cost=0.00..142.62 rows=1,561 width=8) (actual rows= loops=)

  • Filter: ((rates_type)::text = 'custom'::text)