explain.depesz.com

PostgreSQL's explain analyze made readable

Result: inpv

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

Hash Left Join (cost=2,162,132.72..2,231,472.21 rows=165,528 width=140) (actual rows= loops=)

  • Hash Cond: ((projects.account_id = cost_exchange_rates.account_id) AND ((staff_memberships_1.currency)::text = (cost_exchange_rates.currency)::text))
  • Join Filter: ((cost_exchange_rates.start_date <= "*SELECT* 1_1".date) AND (cost_exchange_rates.end_date >= "*SELECT* 1_1".date))
2. 0.000 0.000 ↓ 0.0

Hash Left Join (cost=2,162,088.07..2,216,927.34 rows=165,528 width=176) (actual rows= loops=)

  • Hash Cond: ((projects.account_id = exchange_rates_by_months.account_id) AND (("*SELECT* 1".currency)::text = (exchange_rates_by_months.currency)::text))
  • Join Filter: ((exchange_rates_by_months.start_date <= "*SELECT* 1_1".date) AND (exchange_rates_by_months.end_date >= "*SELECT* 1_1".date))
3. 0.000 0.000 ↓ 0.0

Merge Left Join (cost=2,162,043.42..2,204,865.40 rows=165,528 width=168) (actual rows= loops=)

  • Merge Cond: (projects.id = discounts.project_id)
  • Join Filter: (("*SELECT* 1_1".date >= discounts.start_date) AND ("*SELECT* 1_1".date <= discounts.end_date) AND (((discounts.discountable_id = "*SELECT* 1_1".user_id) AND ((discounts.discountable_type)::text = 'User'::text)) OR ((discounts.discountable_id = "*SELECT* 1_1".epic_id) AND ((discounts.discountable_type)::text = 'Epic'::text))))
4. 0.000 0.000 ↓ 0.0

Merge Join (cost=2,162,020.65..2,196,831.07 rows=165,528 width=164) (actual rows= loops=)

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

Sort (cost=2,115,189.73..2,115,730.68 rows=216,380 width=136) (actual rows= loops=)

  • Sort Key: projects.id, (COALESCE(""*SELECT* 1_1"".activity_id, staff_membership_activity_links.activity_id))
6. 0.000 0.000 ↓ 0.0

Hash Join (cost=1,560,286.62..2,096,015.00 rows=216,380 width=136) (actual rows= loops=)

  • Hash Cond: (projects.account_id = accounts.id)
7. 0.000 0.000 ↓ 0.0

Append (cost=1,560,267.95..2,087,780.52 rows=649,141 width=136) (actual rows= loops=)

8. 0.000 0.000 ↓ 0.0

Hash Join (cost=1,560,267.95..1,590,070.15 rows=403,983 width=108) (actual rows= loops=)

  • Hash Cond: (projects.account_id = accounts_1.id)
  • Join Filter: ((((""*SELECT* 1_1"".vacation_user_id)::double precision) IS NULL) OR (((""*SELECT* 1_1"".vacation_hours)::double precision) < (COALESCE(staff_membership_activity_links.capacity, accounts_1.default_capacity))::double precision))
9. 0.000 0.000 ↓ 0.0

Merge Left Join (cost=1,560,248.98..1,571,733.55 rows=1,199,950 width=144) (actual rows= loops=)

  • Merge Cond: ((projects.account_id = staff_memberships_1.account_id) AND ("*SELECT* 1_1".user_id = staff_memberships_1.user_id))
  • Join Filter: ((""*SELECT* 1_1"".date >= (COALESCE(staff_membership_activity_links.start_date, staff_memberships_1.joined_at))) AND (""*SELECT* 1_1"".date <= (COALESCE(lag((staff_membership_activity_links.start_date - 1), 1) OVER (?), staff_memberships_1.archived_at, '3000-01-01'::date))))
10. 0.000 0.000 ↓ 0.0

Sort (cost=1,559,401.84..1,562,401.72 rows=1,199,950 width=120) (actual rows= loops=)

  • Sort Key: projects.account_id, ""*SELECT* 1_1"".user_id
11. 0.000 0.000 ↓ 0.0

Hash Join (cost=1,131,915.40..1,438,239.63 rows=1,199,950 width=120) (actual rows= loops=)

  • Hash Cond: ("*SELECT* 1_1".project_id = projects.id)
12. 0.000 0.000 ↓ 0.0

Append (cost=1,131,686.63..1,422,859.20 rows=1,199,950 width=116) (actual rows= loops=)

13. 0.000 0.000 ↓ 0.0

Result (cost=1,131,686.63..1,226,655.23 rows=495,989 width=116) (actual rows= loops=)

14. 0.000 0.000 ↓ 0.0

Append (cost=1,131,686.63..1,220,455.37 rows=495,989 width=140) (actual rows= loops=)

15. 0.000 0.000 ↓ 0.0

Subquery Scan on *SELECT* 1_1 (cost=1,131,686.63..1,155,495.07 rows=457,239 width=114) (actual rows= loops=)

16. 0.000 0.000 ↓ 0.0

Merge Left Join (cost=1,131,686.63..1,148,636.49 rows=457,239 width=134) (actual rows= loops=)

  • Merge Cond: ((projects_1.account_id = summary_vacations_by_dates.account_id) AND (generate_series.generate_series = summary_vacations_by_dates.date) AND (plan_rows.user_id = summary_vacations_by_dates.user_id))
17. 0.000 0.000 ↓ 0.0

Merge Anti Join (cost=525,089.35..531,687.96 rows=457,239 width=66) (actual rows= loops=)

  • Merge Cond: ((projects_1.account_id = non_working_intervals_by_dates.account_id) AND (generate_series.generate_series = non_working_intervals_by_dates.date) AND (plan_rows.user_id = non_working_intervals_by_dates.user_id))
18. 0.000 0.000 ↓ 0.0

Sort (cost=519,071.36..520,519.29 rows=579,175 width=66) (actual rows= loops=)

  • Sort Key: projects_1.account_id, generate_series.generate_series, plan_rows.user_id
19. 0.000 0.000 ↓ 0.0

Merge Left Join (cost=12,929.64..463,633.77 rows=579,175 width=66) (actual rows= loops=)

  • Merge Cond: (plan_items.plan_row_uuid = pa.plan_row_uuid)
  • Join Filter: (((pa.epic_id = plan_rows.epic_id) OR (plan_rows.epic_id IS NULL)) AND (pa.project_plan_id = project_plans.id) AND (pa.user_id = plan_rows.user_id) AND ((generate_series.generate_series)::date >= pa.start_date) AND ((generate_series.generate_series)::date <= pa.end_date))
20. 0.000 0.000 ↓ 0.0

Nested Loop (cost=3,971.09..448,257.03 rows=579,175 width=70) (actual rows= loops=)

21. 0.000 0.000 ↓ 0.0

Merge Join (cost=3,971.09..8,084.02 rows=23,167 width=70) (actual rows= loops=)

  • Merge Cond: (plan_rows.uuid = plan_items.plan_row_uuid)
22. 0.000 0.000 ↓ 0.0

Index Scan using plan_rows_uuid_key on plan_rows (cost=0.29..3,663.60 rows=42,428 width=28) (actual rows= loops=)

  • Filter: (user_id IS NOT NULL)
23. 0.000 0.000 ↓ 0.0

Sort (cost=3,970.18..4,035.85 rows=26,267 width=58) (actual rows= loops=)

  • Sort Key: plan_items.plan_row_uuid
24. 0.000 0.000 ↓ 0.0

Hash Join (cost=430.80..2,042.06 rows=26,267 width=58) (actual rows= loops=)

  • Hash Cond: (project_plans.project_id = projects_1.id)
25. 0.000 0.000 ↓ 0.0

Hash Join (cost=202.03..1,744.28 rows=26,267 width=54) (actual rows= loops=)

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

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

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

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

28. 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
29. 0.000 0.000 ↓ 0.0

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

30. 0.000 0.000 ↓ 0.0

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

31. 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[]))
32. 0.000 0.000 ↓ 0.0

Sort (cost=8,958.54..8,970.97 rows=4,971 width=36) (actual rows= loops=)

  • Sort Key: pa.plan_row_uuid
33. 0.000 0.000 ↓ 0.0

Subquery Scan on pa (cost=8,529.07..8,653.34 rows=4,971 width=36) (actual rows= loops=)

34. 0.000 0.000 ↓ 0.0

HashAggregate (cost=8,529.07..8,603.63 rows=4,971 width=48) (actual rows= loops=)

  • Group Key: plan_rows_1.project_plan_id, plan_rows_1.epic_id, plan_rows_1.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)
35. 0.000 0.000 ↓ 0.0

WindowAgg (cost=6,077.00..7,080.12 rows=44,583 width=68) (actual rows= loops=)

36. 0.000 0.000 ↓ 0.0

Sort (cost=6,077.00..6,188.46 rows=44,583 width=52) (actual rows= loops=)

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

Hash Join (cost=1,631.38..2,634.26 rows=44,583 width=52) (actual rows= loops=)

  • Hash Cond: (plan_roles.plan_row_uuid = plan_rows_1.uuid)
38. 0.000 0.000 ↓ 0.0

Seq Scan on plan_roles (cost=0.00..885.83 rows=44,583 width=24) (actual rows= loops=)

39. 0.000 0.000 ↓ 0.0

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

40. 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=)

41. 0.000 0.000 ↓ 0.0

Sort (cost=6,017.99..6,167.27 rows=59,712 width=12) (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
42. 0.000 0.000 ↓ 0.0

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

43. 0.000 0.000 ↓ 0.0

Sort (cost=606,597.28..608,034.78 rows=575,000 width=44) (actual rows= loops=)

  • Sort Key: summary_vacations_by_dates.account_id, summary_vacations_by_dates.date, summary_vacations_by_dates.user_id
44. 0.000 0.000 ↓ 0.0

Subquery Scan on summary_vacations_by_dates (cost=537,214.32..551,589.32 rows=575,000 width=44) (actual rows= loops=)

45. 0.000 0.000 ↓ 0.0

HashAggregate (cost=537,214.32..545,839.32 rows=575,000 width=52) (actual rows= loops=)

  • Group Key: generate_series_1.generate_series, staff_memberships.user_id, staff_memberships.account_id
46. 0.000 0.000 ↓ 0.0

Hash Join (cost=138.05..493,700.50 rows=4,351,382 width=21) (actual rows= loops=)

  • Hash Cond: (vacations.staff_membership_id = staff_memberships.id)
  • Join Filter: ((generate_series_1.generate_series >= staff_memberships.joined_at) AND ((staff_memberships.archived_at IS NULL) OR (generate_series_1.generate_series <= staff_memberships.archived_at)))
47. 0.000 0.000 ↓ 0.0

Nested Loop (cost=0.01..436,340.93 rows=21,792,000 width=17) (actual rows= loops=)

48. 0.000 0.000 ↓ 0.0

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

49. 0.000 0.000 ↓ 0.0

Function Scan on generate_series generate_series_1 (cost=0.01..10.01 rows=1,000 width=8) (actual rows= loops=)

50. 0.000 0.000 ↓ 0.0

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

51. 0.000 0.000 ↓ 0.0

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

52. 0.000 0.000 ↓ 0.0

Hash Join (cost=1,215.85..62,092.86 rows=38,750 width=114) (actual rows= loops=)

  • Hash Cond: (project_plans_1.project_id = projects_1_1.id)
  • Join Filter: (NOT (SubPlan 1))
53. 0.000 0.000 ↓ 0.0

Nested Loop (cost=987.08..61,446.50 rows=77,500 width=58) (actual rows= loops=)

54. 0.000 0.000 ↓ 0.0

Hash Join (cost=987.08..2,546.49 rows=3,100 width=58) (actual rows= loops=)

  • Hash Cond: (plan_items_1.project_plan_id = project_plans_1.id)
55. 0.000 0.000 ↓ 0.0

Hash Join (cost=785.05..2,327.21 rows=6,567 width=54) (actual rows= loops=)

  • Hash Cond: (plan_items_1.plan_row_uuid = plan_rows_2.uuid)
56. 0.000 0.000 ↓ 0.0

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

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

Hash (cost=714.07..714.07 rows=5,678 width=24) (actual rows= loops=)

58. 0.000 0.000 ↓ 0.0

Bitmap Heap Scan on plan_rows plan_rows_2 (cost=108.29..714.07 rows=5,678 width=24) (actual rows= loops=)

  • Recheck Cond: (user_id IS NULL)
59. 0.000 0.000 ↓ 0.0

Bitmap Index Scan on index_plan_rows_on_user_id (cost=0.00..106.88 rows=5,678 width=0) (actual rows= loops=)

  • Index Cond: (user_id IS NULL)
60. 0.000 0.000 ↓ 0.0

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

61. 0.000 0.000 ↓ 0.0

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

  • Filter: active
62. 0.000 0.000 ↓ 0.0

Function Scan on generate_series generate_series_2 (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[]))
63. 0.000 0.000 ↓ 0.0

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

64. 0.000 0.000 ↓ 0.0

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

65.          

SubPlan (for Hash Join)

66. 0.000 0.000 ↓ 0.0

Nested Loop (cost=0.69..16.74 rows=1 width=0) (actual rows= loops=)

67. 0.000 0.000 ↓ 0.0

Index Scan using clients_pkey on clients clients_3 (cost=0.28..8.29 rows=1 width=4) (actual rows= loops=)

  • Index Cond: (projects_1_1.client_id = id)
68. 0.000 0.000 ↓ 0.0

Index Only Scan using non_working_intervals_by_office_id_idx on non_working_intervals_by_dates non_working_intervals_by_dates_2 (cost=0.41..8.44 rows=1 width=4) (actual rows= loops=)

  • Index Cond: ((account_id = projects_1_1.account_id) AND (office_id = clients_3.office_id) AND (date = generate_series_2.generate_series))
69. 0.000 0.000 ↓ 0.0

Hash Right Join (cost=45,029.23..183,164.61 rows=703,961 width=116) (actual rows= loops=)

  • Hash Cond: (plan_rows_3.user_id = time_logs.user_id)
  • Join Filter: ((time_logs.date >= (COALESCE(plan_roles_1.start_date, '1980-01-01'::date))) AND (time_logs.date <= (COALESCE(lag((plan_roles_1.start_date - 1), 1) OVER (?), '3000-01-01'::date))) AND (((plan_rows_3.epic_id = time_logs.epic_id) AND (plan_rows_3.project_plan_id = epics.project_plan_id)) OR ((plan_rows_3.epic_id IS NULL) AND (plan_rows_3.project_plan_id = general_epic_plans.id))))
70. 0.000 0.000 ↓ 0.0

HashAggregate (cost=8,529.07..8,603.63 rows=4,971 width=48) (actual rows= loops=)

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

WindowAgg (cost=6,077.00..7,080.12 rows=44,583 width=68) (actual rows= loops=)

72. 0.000 0.000 ↓ 0.0

Sort (cost=6,077.00..6,188.46 rows=44,583 width=52) (actual rows= loops=)

  • Sort Key: plan_roles_1.plan_row_uuid, plan_roles_1.start_date DESC NULLS LAST
73. 0.000 0.000 ↓ 0.0

Hash Join (cost=1,631.38..2,634.26 rows=44,583 width=52) (actual rows= loops=)

  • Hash Cond: (plan_roles_1.plan_row_uuid = plan_rows_3.uuid)
74. 0.000 0.000 ↓ 0.0

Seq Scan on plan_roles plan_roles_1 (cost=0.00..885.83 rows=44,583 width=24) (actual rows= loops=)

75. 0.000 0.000 ↓ 0.0

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

76. 0.000 0.000 ↓ 0.0

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

77. 0.000 0.000 ↓ 0.0

Hash (cost=27,700.65..27,700.65 rows=703,961 width=40) (actual rows= loops=)

78. 0.000 0.000 ↓ 0.0

Hash Join (cost=1,826.58..27,700.65 rows=703,961 width=40) (actual rows= loops=)

  • Hash Cond: (time_logs.epic_id = epics.id)
79. 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=)

80. 0.000 0.000 ↓ 0.0

Hash (cost=1,496.14..1,496.14 rows=26,435 width=16) (actual rows= loops=)

81. 0.000 0.000 ↓ 0.0

Hash Left Join (cost=202.03..1,496.14 rows=26,435 width=16) (actual rows= loops=)

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

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

83. 0.000 0.000 ↓ 0.0

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

84. 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
85. 0.000 0.000 ↓ 0.0

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

86. 0.000 0.000 ↓ 0.0

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

87. 0.000 0.000 ↓ 0.0

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

88. 0.000 0.000 ↓ 0.0

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

89. 0.000 0.000 ↓ 0.0

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

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

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

91. 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
92. 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_1.id)
93. 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=)

94. 0.000 0.000 ↓ 0.0

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

95. 0.000 0.000 ↓ 0.0

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

96. 0.000 0.000 ↓ 0.0

Hash (cost=14.54..14.54 rows=354 width=9) (actual rows= loops=)

97. 0.000 0.000 ↓ 0.0

Seq Scan on accounts accounts_1 (cost=0.00..14.54 rows=354 width=9) (actual rows= loops=)

98. 0.000 0.000 ↓ 0.0

Subquery Scan on *SELECT* 2_1 (cost=3,354.66..490,424.84 rows=245,158 width=136) (actual rows= loops=)

99. 0.000 0.000 ↓ 0.0

Hash Anti Join (cost=3,354.66..487,360.36 rows=245,158 width=143) (actual rows= loops=)

  • Hash Cond: ((sa.account_id = non_working_intervals_by_dates_1.account_id) AND (sa.user_id = non_working_intervals_by_dates_1.user_id))
  • Join Filter: (generate_series_3.generate_series = non_working_intervals_by_dates_1.date)
100. 0.000 0.000 ↓ 0.0

Merge Join (cost=1,177.86..468,661.53 rows=280,181 width=64) (actual rows= loops=)

  • Merge Cond: (vacations_1.staff_membership_id = sa.staff_membership_id)
  • Join Filter: ((generate_series_3.generate_series >= sa.start_date) AND (generate_series_3.generate_series <= sa.end_date))
101. 0.000 0.000 ↓ 0.0

Nested Loop (cost=0.29..415,689.39 rows=544,800 width=44) (actual rows= loops=)

102. 0.000 0.000 ↓ 0.0

Index Scan using index_vacations_on_staff_membership_id on vacations vacations_1 (cost=0.29..1,641.38 rows=21,792 width=44) (actual rows= loops=)

103. 0.000 0.000 ↓ 0.0

Function Scan on generate_series generate_series_3 (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[]))
104. 0.000 0.000 ↓ 0.0

Sort (cost=1,177.56..1,188.19 rows=4,249 width=36) (actual rows= loops=)

  • Sort Key: sa.staff_membership_id
105. 0.000 0.000 ↓ 0.0

Subquery Scan on sa (cost=836.52..921.50 rows=4,249 width=36) (actual rows= loops=)

106. 0.000 0.000 ↓ 0.0

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

107. 0.000 0.000 ↓ 0.0

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

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

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

109. 0.000 0.000 ↓ 0.0

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

  • Sort Key: staff_membership_activity_links_1.staff_membership_id, staff_membership_activity_links_1.start_date DESC NULLS LAST
110. 0.000 0.000 ↓ 0.0

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

  • Hash Cond: (staff_membership_activity_links_1.staff_membership_id = staff_memberships_2.id)
111. 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=)

112. 0.000 0.000 ↓ 0.0

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

113. 0.000 0.000 ↓ 0.0

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

114. 0.000 0.000 ↓ 0.0

Hash (cost=1,281.12..1,281.12 rows=59,712 width=12) (actual rows= loops=)

115. 0.000 0.000 ↓ 0.0

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

116. 0.000 0.000 ↓ 0.0

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

117. 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)
118. 0.000 0.000 ↓ 0.0

Sort (cost=46,830.92..47,512.59 rows=272,669 width=44) (actual rows= loops=)

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

Append (cost=300.88..22,213.28 rows=272,669 width=44) (actual rows= loops=)

120. 0.000 0.000 ↓ 0.0

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

121. 0.000 0.000 ↓ 0.0

Merge Join (cost=300.88..470.13 rows=49 width=612) (actual rows= loops=)

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

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

123. 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)
124. 0.000 0.000 ↓ 0.0

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

125. 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
126. 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)
127. 0.000 0.000 ↓ 0.0

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

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

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

129. 0.000 0.000 ↓ 0.0

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

130. 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)
131. 0.000 0.000 ↓ 0.0

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

  • Index Cond: (id = pricing_models.project_id)
132. 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_2.client_id)
133. 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.55 rows=49 width=28) (actual rows= loops=)

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

Sort (cost=6.09..6.37 rows=115 width=4) (actual rows= loops=)

  • Sort Key: brands.id
135. 0.000 0.000 ↓ 0.0

Seq Scan on brands (cost=0.00..2.15 rows=115 width=4) (actual rows= loops=)

136. 0.000 0.000 ↓ 0.0

Subquery Scan on *SELECT* 2 (cost=583.00..5,484.31 rows=35,240 width=44) (actual rows= loops=)

137. 0.000 0.000 ↓ 0.0

Hash Join (cost=583.00..5,131.91 rows=35,240 width=612) (actual rows= loops=)

  • Hash Cond: (rates_1.rate_card_id = rate_cards_1.id)
138. 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=)

139. 0.000 0.000 ↓ 0.0

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

140. 0.000 0.000 ↓ 0.0

Hash Join (cost=378.98..574.00 rows=720 width=24) (actual rows= loops=)

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

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

  • Hash Cond: (projects_3.client_id = clients_1.id)
142. 0.000 0.000 ↓ 0.0

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

  • Hash Cond: (projects_3.id = pricing_models_1.project_id)
143. 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=)

144. 0.000 0.000 ↓ 0.0

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

145. 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)
146. 0.000 0.000 ↓ 0.0

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

147. 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=)

148. 0.000 0.000 ↓ 0.0

Hash (cost=158.85..158.85 rows=489 width=28) (actual rows= loops=)

149. 0.000 0.000 ↓ 0.0

Hash Join (cost=140.44..158.85 rows=489 width=28) (actual rows= loops=)

  • Hash Cond: (rate_cards_1.rateable_id = offices.id)
150. 0.000 0.000 ↓ 0.0

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

151. 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
152. 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)
153. 0.000 0.000 ↓ 0.0

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

154. 0.000 0.000 ↓ 0.0

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

155. 0.000 0.000 ↓ 0.0

Subquery Scan on *SELECT* 3 (cost=840.78..9,363.71 rows=205,419 width=44) (actual rows= loops=)

156. 0.000 0.000 ↓ 0.0

Hash Join (cost=840.78..7,309.52 rows=205,419 width=612) (actual rows= loops=)

  • Hash Cond: (rates_2.rate_card_id = rate_cards_2.id)
157. 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=)

158. 0.000 0.000 ↓ 0.0

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

159. 0.000 0.000 ↓ 0.0

Hash Join (cost=586.95..788.31 rows=4,197 width=24) (actual rows= loops=)

  • Hash Cond: (projects_4.client_id = clients_2.id)
160. 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_4.id)
161. 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)
162. 0.000 0.000 ↓ 0.0

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

163. 0.000 0.000 ↓ 0.0

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

164. 0.000 0.000 ↓ 0.0

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

165. 0.000 0.000 ↓ 0.0

Hash Join (cost=266.89..335.42 rows=1,821 width=28) (actual rows= loops=)

  • Hash Cond: (rate_cards_2.rateable_id = clients_2.id)
166. 0.000 0.000 ↓ 0.0

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

167. 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
168. 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)
169. 0.000 0.000 ↓ 0.0

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

170. 0.000 0.000 ↓ 0.0

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

171. 0.000 0.000 ↓ 0.0

Subquery Scan on *SELECT* 4 (cost=695.56..5,531.29 rows=31,961 width=44) (actual rows= loops=)

172. 0.000 0.000 ↓ 0.0

Hash Join (cost=695.56..5,211.68 rows=31,961 width=612) (actual rows= loops=)

  • Hash Cond: (rates_3.rate_card_id = rate_cards_3.id)
173. 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=)

174. 0.000 0.000 ↓ 0.0

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

175. 0.000 0.000 ↓ 0.0

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

  • Hash Cond: (projects_5.id = pricing_models_3.project_id)
176. 0.000 0.000 ↓ 0.0

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

177. 0.000 0.000 ↓ 0.0

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

178. 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)
179. 0.000 0.000 ↓ 0.0

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

180. 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
181. 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)
182. 0.000 0.000 ↓ 0.0

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

183. 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)
184. 0.000 0.000 ↓ 0.0

Sort (cost=22.77..23.53 rows=306 width=26) (actual rows= loops=)

  • Sort Key: discounts.project_id
185. 0.000 0.000 ↓ 0.0

Seq Scan on discounts (cost=0.00..10.13 rows=306 width=26) (actual rows= loops=)

  • Filter: (((discountable_type)::text = 'User'::text) OR ((discountable_type)::text = 'Epic'::text))
186. 0.000 0.000 ↓ 0.0

Hash (cost=40.66..40.66 rows=266 width=536) (actual rows= loops=)

187. 0.000 0.000 ↓ 0.0

Seq Scan on exchange_rates_by_months (cost=0.00..40.66 rows=266 width=536) (actual rows= loops=)

188. 0.000 0.000 ↓ 0.0

Hash (cost=40.66..40.66 rows=266 width=536) (actual rows= loops=)

189. 0.000 0.000 ↓ 0.0

Seq Scan on exchange_rates_by_months cost_exchange_rates (cost=0.00..40.66 rows=266 width=536) (actual rows= loops=)