explain.depesz.com

PostgreSQL's explain analyze made readable

Result: yh0r

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

Merge Left Join (cost=1,492,714.01..1,501,038.81 rows=5,656 width=188) (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)))
2. 0.000 0.000 ↓ 0.0

Sort (cost=1,445,697.84..1,445,711.98 rows=5,656 width=136) (actual rows= loops=)

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

Hash Join (cost=1,443,543.41..1,445,345.31 rows=5,656 width=136) (actual rows= loops=)

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

Append (cost=1,443,514.74..1,445,101.89 rows=16,968 width=136) (actual rows= loops=)

5. 0.000 0.000 ↓ 0.0

Hash Join (cost=1,443,514.74..1,444,847.38 rows=16,967 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))
6. 0.000 0.000 ↓ 0.0

Merge Left Join (cost=1,443,485.77..1,444,049.08 rows=50,397 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))))
7. 0.000 0.000 ↓ 0.0

Sort (cost=1,442,627.56..1,442,753.55 rows=50,397 width=120) (actual rows= loops=)

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

Hash Join (cost=1,127,079.61..1,438,691.29 rows=50,397 width=120) (actual rows= loops=)

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

Append (cost=1,126,498.49..1,423,043.52 rows=1,193,215 width=116) (actual rows= loops=)

10. 0.000 0.000 ↓ 0.0

Result (cost=1,126,498.49..1,221,784.06 rows=492,894 width=116) (actual rows= loops=)

11. 0.000 0.000 ↓ 0.0

Append (cost=1,126,498.49..1,215,622.88 rows=492,894 width=140) (actual rows= loops=)

12. 0.000 0.000 ↓ 0.0

Subquery Scan on *SELECT* 1_1 (cost=1,126,498.49..1,150,184.42 rows=454,419 width=114) (actual rows= loops=)

13. 0.000 0.000 ↓ 0.0

Merge Left Join (cost=1,126,498.49..1,143,368.14 rows=454,419 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))
14. 0.000 0.000 ↓ 0.0

Merge Anti Join (cost=523,636.65..530,200.98 rows=454,419 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))
15. 0.000 0.000 ↓ 0.0

Sort (cost=517,568.00..519,007.82 rows=575,925 width=66) (actual rows= loops=)

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

Merge Left Join (cost=13,858.16..462,464.88 rows=575,925 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))
17. 0.000 0.000 ↓ 0.0

Nested Loop (cost=4,105.29..446,324.10 rows=575,925 width=70) (actual rows= loops=)

18. 0.000 0.000 ↓ 0.0

Merge Join (cost=4,105.28..8,621.10 rows=23,037 width=70) (actual rows= loops=)

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

Index Scan using index_plan_rows_on_uuid on plan_rows (cost=0.29..4,050.51 rows=42,108 width=28) (actual rows= loops=)

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

Sort (cost=4,104.99..4,170.28 rows=26,115 width=58) (actual rows= loops=)

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

Hash Join (cost=550.77..2,189.12 rows=26,115 width=58) (actual rows= loops=)

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

Hash Join (cost=208.79..1,778.53 rows=26,115 width=54) (actual rows= loops=)

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

Seq Scan on plan_items (cost=0.00..1,425.72 rows=54,823 width=46) (actual rows= loops=)

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

Hash (cost=173.04..173.04 rows=2,860 width=8) (actual rows= loops=)

25. 0.000 0.000 ↓ 0.0

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

  • Filter: active
26. 0.000 0.000 ↓ 0.0

Hash (cost=269.77..269.77 rows=5,777 width=8) (actual rows= loops=)

27. 0.000 0.000 ↓ 0.0

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

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

Sort (cost=9,752.87..9,765.18 rows=4,926 width=36) (actual rows= loops=)

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

Subquery Scan on pa (cost=9,327.60..9,450.75 rows=4,926 width=36) (actual rows= loops=)

31. 0.000 0.000 ↓ 0.0

HashAggregate (cost=9,327.60..9,401.49 rows=4,926 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)
32. 0.000 0.000 ↓ 0.0

WindowAgg (cost=6,892.75..7,888.83 rows=44,270 width=68) (actual rows= loops=)

33. 0.000 0.000 ↓ 0.0

Sort (cost=6,892.75..7,003.43 rows=44,270 width=52) (actual rows= loops=)

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

Hash Join (cost=1,661.02..3,476.43 rows=44,270 width=52) (actual rows= loops=)

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

Seq Scan on plan_roles (cost=0.00..1,206.70 rows=44,270 width=24) (actual rows= loops=)

36. 0.000 0.000 ↓ 0.0

Hash (cost=1,064.34..1,064.34 rows=47,734 width=28) (actual rows= loops=)

37. 0.000 0.000 ↓ 0.0

Seq Scan on plan_rows plan_rows_1 (cost=0.00..1,064.34 rows=47,734 width=28) (actual rows= loops=)

38. 0.000 0.000 ↓ 0.0

Sort (cost=6,068.65..6,217.17 rows=59,408 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
39. 0.000 0.000 ↓ 0.0

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

40. 0.000 0.000 ↓ 0.0

Sort (cost=602,861.83..604,294.83 rows=573,200 width=44) (actual rows= loops=)

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

Subquery Scan on summary_vacations_by_dates (cost=533,709.04..548,039.04 rows=573,200 width=44) (actual rows= loops=)

42. 0.000 0.000 ↓ 0.0

HashAggregate (cost=533,709.04..542,307.04 rows=573,200 width=52) (actual rows= loops=)

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

Hash Join (cost=145.85..490,443.54 rows=4,326,550 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)))
44. 0.000 0.000 ↓ 0.0

Nested Loop (cost=0.01..433,459.47 rows=21,646,000 width=17) (actual rows= loops=)

45. 0.000 0.000 ↓ 0.0

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

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

47. 0.000 0.000 ↓ 0.0

Hash (cost=95.93..95.93 rows=3,993 width=20) (actual rows= loops=)

48. 0.000 0.000 ↓ 0.0

Seq Scan on staff_memberships (cost=0.00..95.93 rows=3,993 width=20) (actual rows= loops=)

49. 0.000 0.000 ↓ 0.0

Hash Join (cost=1,420.26..62,589.24 rows=38,475 width=114) (actual rows= loops=)

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

Nested Loop (cost=1,078.27..61,258.72 rows=76,950 width=58) (actual rows= loops=)

51. 0.000 0.000 ↓ 0.0

Hash Join (cost=1,078.27..2,776.71 rows=3,078 width=58) (actual rows= loops=)

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

Hash Join (cost=208.79..1,778.53 rows=26,115 width=50) (actual rows= loops=)

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

Seq Scan on plan_items plan_items_1 (cost=0.00..1,425.72 rows=54,823 width=46) (actual rows= loops=)

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

Hash (cost=173.04..173.04 rows=2,860 width=8) (actual rows= loops=)

55. 0.000 0.000 ↓ 0.0

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

  • Filter: active
56. 0.000 0.000 ↓ 0.0

Hash (cost=799.15..799.15 rows=5,626 width=24) (actual rows= loops=)

57. 0.000 0.000 ↓ 0.0

Bitmap Heap Scan on plan_rows plan_rows_2 (cost=155.89..799.15 rows=5,626 width=24) (actual rows= loops=)

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

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

  • Index Cond: (user_id IS NULL)
59. 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[]))
60. 0.000 0.000 ↓ 0.0

Hash (cost=269.77..269.77 rows=5,777 width=12) (actual rows= loops=)

61. 0.000 0.000 ↓ 0.0

Seq Scan on projects project (cost=0.00..269.77 rows=5,777 width=12) (actual rows= loops=)

62.          

SubPlan (for Hash Join)

63. 0.000 0.000 ↓ 0.0

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

  • Join Filter: (non_working_intervals_by_dates_1.office_id = clients_3.office_id)
64. 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: (project.client_id = id)
65. 0.000 0.000 ↓ 0.0

Index Scan using non_working_intervals_by_dates_idx on non_working_intervals_by_dates non_working_intervals_by_dates_1 (cost=0.41..90.18 rows=11 width=4) (actual rows= loops=)

  • Index Cond: ((project.account_id = account_id) AND (generate_series_2.generate_series = date))
66. 0.000 0.000 ↓ 0.0

Hash Right Join (cost=48,474.22..188,290.18 rows=700,321 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 = active_plan.id))))
67. 0.000 0.000 ↓ 0.0

HashAggregate (cost=9,327.60..9,401.49 rows=4,926 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)
68. 0.000 0.000 ↓ 0.0

WindowAgg (cost=6,892.75..7,888.83 rows=44,270 width=68) (actual rows= loops=)

69. 0.000 0.000 ↓ 0.0

Sort (cost=6,892.75..7,003.43 rows=44,270 width=52) (actual rows= loops=)

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

Hash Join (cost=1,661.02..3,476.43 rows=44,270 width=52) (actual rows= loops=)

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

Seq Scan on plan_roles plan_roles_1 (cost=0.00..1,206.70 rows=44,270 width=24) (actual rows= loops=)

72. 0.000 0.000 ↓ 0.0

Hash (cost=1,064.34..1,064.34 rows=47,734 width=28) (actual rows= loops=)

73. 0.000 0.000 ↓ 0.0

Seq Scan on plan_rows plan_rows_3 (cost=0.00..1,064.34 rows=47,734 width=28) (actual rows= loops=)

74. 0.000 0.000 ↓ 0.0

Hash (cost=30,392.60..30,392.60 rows=700,321 width=40) (actual rows= loops=)

75. 0.000 0.000 ↓ 0.0

Hash Left Join (cost=1,912.98..30,392.60 rows=700,321 width=40) (actual rows= loops=)

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

Seq Scan on time_logs (cost=0.00..18,850.21 rows=700,321 width=28) (actual rows= loops=)

77. 0.000 0.000 ↓ 0.0

Hash (cost=1,583.78..1,583.78 rows=26,336 width=16) (actual rows= loops=)

78. 0.000 0.000 ↓ 0.0

Hash Left Join (cost=208.79..1,583.78 rows=26,336 width=16) (actual rows= loops=)

  • Hash Cond: (epics.project_id = active_plan.project_id)
79. 0.000 0.000 ↓ 0.0

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

80. 0.000 0.000 ↓ 0.0

Hash (cost=173.04..173.04 rows=2,860 width=8) (actual rows= loops=)

81. 0.000 0.000 ↓ 0.0

Seq Scan on project_plans active_plan (cost=0.00..173.04 rows=2,860 width=8) (actual rows= loops=)

  • Filter: active
82. 0.000 0.000 ↓ 0.0

Hash (cost=578.08..578.08 rows=244 width=8) (actual rows= loops=)

83. 0.000 0.000 ↓ 0.0

Bitmap Heap Scan on projects (cost=278.82..578.08 rows=244 width=8) (actual rows= loops=)

  • Recheck Cond: (id = ANY ('{10025,10038,10047,10082,10339,10430,10431,10488,10491,10507,10508,10512,10519,10571,10595,10645,10650,10651,10674,10729,10802,10808,10811,10851,10885,10897,10935,10954,10955,10969,10985,10996,11038,11044,11045,11107,11321,11323,11410,11420,11424,11425,11442,11447,11448,11482,11500,11505,11509,11512,11537,11540,11543,11547,11562,11565,11566,11569,11570,11579,11582,11583,11585,11586,11592,11593,11594,11596,11597,11599,11601,11603,11604,11605,11607,11614,11621,11623,11626,11627,11633,11634,11636,11645,11653,11684,11835,11900,11904,11910,11913,11915,11951,11953,11959,11970,11989,11992,11996,12003,12010,12049,12056,13023,13026,13027,13028,13029,13459,13481,13482,13485,13487,13545,13565,13882,13935,13946,13947,13977,13986,13994,14001,14004,14020,14027,14034,14066,14078,14084,14085,14086,14087,14100,14101,14106,14114,14123,14128,14129,14137,14149,14162,14214,14217,14218,14219,14230,14256,14285,14310,14352,14360,14426,14447,14450,14461,14468,14469,14472,14491,14527,14585,14590,14600,14604,14637,14644,14659,14699,14731,14733,14736,14764,14780,14810,14815,14820,14849,14875,14897,14904,14958,14962,15036,15041,15083,15092,15140,15152,15183,15191,15282,15283,15384,15517,15518,15530,15551,15565,15572,15585,15586,15597,15600,15621,15622,15638,15640,15641,15642,15644,15647,15671,15679,15683,15684,15692,15694,15742,15753,15772,15784,15785,15811,15814,15826,15864,15887,15914,15915,15938,15939,15944,15945,15958,15966,16002,16008,16009,16033,16034,16049,16061}'::integer[]))
84. 0.000 0.000 ↓ 0.0

Bitmap Index Scan on projects_pkey (cost=0.00..278.76 rows=244 width=0) (actual rows= loops=)

  • Index Cond: (id = ANY ('{10025,10038,10047,10082,10339,10430,10431,10488,10491,10507,10508,10512,10519,10571,10595,10645,10650,10651,10674,10729,10802,10808,10811,10851,10885,10897,10935,10954,10955,10969,10985,10996,11038,11044,11045,11107,11321,11323,11410,11420,11424,11425,11442,11447,11448,11482,11500,11505,11509,11512,11537,11540,11543,11547,11562,11565,11566,11569,11570,11579,11582,11583,11585,11586,11592,11593,11594,11596,11597,11599,11601,11603,11604,11605,11607,11614,11621,11623,11626,11627,11633,11634,11636,11645,11653,11684,11835,11900,11904,11910,11913,11915,11951,11953,11959,11970,11989,11992,11996,12003,12010,12049,12056,13023,13026,13027,13028,13029,13459,13481,13482,13485,13487,13545,13565,13882,13935,13946,13947,13977,13986,13994,14001,14004,14020,14027,14034,14066,14078,14084,14085,14086,14087,14100,14101,14106,14114,14123,14128,14129,14137,14149,14162,14214,14217,14218,14219,14230,14256,14285,14310,14352,14360,14426,14447,14450,14461,14468,14469,14472,14491,14527,14585,14590,14600,14604,14637,14644,14659,14699,14731,14733,14736,14764,14780,14810,14815,14820,14849,14875,14897,14904,14958,14962,15036,15041,15083,15092,15140,15152,15183,15191,15282,15283,15384,15517,15518,15530,15551,15565,15572,15585,15586,15597,15600,15621,15622,15638,15640,15641,15642,15644,15647,15671,15679,15683,15684,15692,15694,15742,15753,15772,15784,15785,15811,15814,15826,15864,15887,15914,15915,15938,15939,15944,15945,15958,15966,16002,16008,16009,16033,16034,16049,16061}'::integer[]))
85. 0.000 0.000 ↓ 0.0

Materialize (cost=858.21..953.59 rows=4,239 width=40) (actual rows= loops=)

86. 0.000 0.000 ↓ 0.0

Unique (cost=858.21..900.60 rows=4,239 width=65) (actual rows= loops=)

87. 0.000 0.000 ↓ 0.0

Sort (cost=858.21..868.81 rows=4,239 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
88. 0.000 0.000 ↓ 0.0

WindowAgg (cost=496.85..602.82 rows=4,239 width=65) (actual rows= loops=)

89. 0.000 0.000 ↓ 0.0

Sort (cost=496.85..507.45 rows=4,239 width=56) (actual rows= loops=)

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

Hash Join (cost=145.84..241.46 rows=4,239 width=56) (actual rows= loops=)

  • Hash Cond: (staff_membership_activity_links.staff_membership_id = staff_memberships_1.id)
91. 0.000 0.000 ↓ 0.0

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

92. 0.000 0.000 ↓ 0.0

Hash (cost=95.93..95.93 rows=3,993 width=32) (actual rows= loops=)

93. 0.000 0.000 ↓ 0.0

Seq Scan on staff_memberships staff_memberships_1 (cost=0.00..95.93 rows=3,993 width=32) (actual rows= loops=)

94. 0.000 0.000 ↓ 0.0

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

95. 0.000 0.000 ↓ 0.0

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

96. 0.000 0.000 ↓ 0.0

Subquery Scan on *SELECT* 2_1 (cost=0.00..0.00 rows=1 width=136) (actual rows= loops=)

97. 0.000 0.000 ↓ 0.0

Result (cost=0.00..0.00 rows=0 width=143) (actual rows= loops=)

  • One-Time Filter: false
98. 0.000 0.000 ↓ 0.0

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

99. 0.000 0.000 ↓ 0.0

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

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

Sort (cost=47,016.17..47,691.28 rows=270,045 width=44) (actual rows= loops=)

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

Append (cost=301.84..22,654.28 rows=270,045 width=44) (actual rows= loops=)

102. 0.000 0.000 ↓ 0.0

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

103. 0.000 0.000 ↓ 0.0

Merge Join (cost=301.84..471.67 rows=49 width=612) (actual rows= loops=)

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

Nested Loop (cost=295.76..1,677.38 rows=49 width=52) (actual rows= loops=)

105. 0.000 0.000 ↓ 0.0

Merge Join (cost=295.34..295.62 rows=1 width=32) (actual rows= loops=)

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

WindowAgg (cost=114.26..117.14 rows=115 width=45) (actual rows= loops=)

107. 0.000 0.000 ↓ 0.0

Sort (cost=114.26..114.55 rows=115 width=29) (actual rows= loops=)

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

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

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

Sort (cost=181.07..181.08 rows=3 width=8) (actual rows= loops=)

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

Nested Loop (cost=0.56..181.05 rows=3 width=8) (actual rows= loops=)

111. 0.000 0.000 ↓ 0.0

Nested Loop (cost=0.28..180.09 rows=3 width=8) (actual rows= loops=)

112. 0.000 0.000 ↓ 0.0

Seq Scan on pricing_models (cost=0.00..155.19 rows=3 width=4) (actual rows= loops=)

  • Filter: ((rates_type)::text = 'brand'::text)
113. 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)
114. 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)
115. 0.000 0.000 ↓ 0.0

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

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

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

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

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

118. 0.000 0.000 ↓ 0.0

Subquery Scan on *SELECT* 2 (cost=716.99..5,638.85 rows=34,420 width=44) (actual rows= loops=)

119. 0.000 0.000 ↓ 0.0

Hash Join (cost=716.99..5,294.65 rows=34,420 width=612) (actual rows= loops=)

  • Hash Cond: (rates_1.rate_card_id = rate_cards_1.id)
120. 0.000 0.000 ↓ 0.0

Seq Scan on rates rates_1 (cost=0.00..3,583.15 rows=173,415 width=28) (actual rows= loops=)

121. 0.000 0.000 ↓ 0.0

Hash (cost=708.17..708.17 rows=706 width=24) (actual rows= loops=)

122. 0.000 0.000 ↓ 0.0

Hash Join (cost=399.95..708.17 rows=706 width=24) (actual rows= loops=)

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

Hash Join (cost=228.34..527.49 rows=611 width=8) (actual rows= loops=)

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

Hash Join (cost=162.82..460.37 rows=611 width=8) (actual rows= loops=)

  • Hash Cond: (projects_3.id = pricing_models_1.project_id)
125. 0.000 0.000 ↓ 0.0

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

126. 0.000 0.000 ↓ 0.0

Hash (cost=155.19..155.19 rows=611 width=4) (actual rows= loops=)

127. 0.000 0.000 ↓ 0.0

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

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

Hash (cost=42.45..42.45 rows=1,845 width=8) (actual rows= loops=)

129. 0.000 0.000 ↓ 0.0

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

130. 0.000 0.000 ↓ 0.0

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

131. 0.000 0.000 ↓ 0.0

Hash Join (cost=147.09..165.50 rows=489 width=28) (actual rows= loops=)

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

WindowAgg (cost=132.17..144.39 rows=489 width=45) (actual rows= loops=)

133. 0.000 0.000 ↓ 0.0

Sort (cost=132.17..133.39 rows=489 width=29) (actual rows= loops=)

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

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

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

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

136. 0.000 0.000 ↓ 0.0

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

137. 0.000 0.000 ↓ 0.0

Subquery Scan on *SELECT* 3 (cost=973.33..9,505.18 rows=204,081 width=44) (actual rows= loops=)

138. 0.000 0.000 ↓ 0.0

Hash Join (cost=973.33..7,464.37 rows=204,081 width=612) (actual rows= loops=)

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

Seq Scan on rates rates_2 (cost=0.00..3,583.15 rows=173,415 width=28) (actual rows= loops=)

140. 0.000 0.000 ↓ 0.0

Hash (cost=921.01..921.01 rows=4,186 width=24) (actual rows= loops=)

141. 0.000 0.000 ↓ 0.0

Hash Join (cost=707.27..921.01 rows=4,186 width=24) (actual rows= loops=)

  • Hash Cond: (projects_4.client_id = clients_2.id)
142. 0.000 0.000 ↓ 0.0

Hash Join (cost=341.98..506.65 rows=3,608 width=8) (actual rows= loops=)

  • Hash Cond: (pricing_models_2.project_id = projects_4.id)
143. 0.000 0.000 ↓ 0.0

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

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

Hash (cost=269.77..269.77 rows=5,777 width=8) (actual rows= loops=)

145. 0.000 0.000 ↓ 0.0

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

146. 0.000 0.000 ↓ 0.0

Hash (cost=342.58..342.58 rows=1,817 width=28) (actual rows= loops=)

147. 0.000 0.000 ↓ 0.0

Hash Join (cost=274.20..342.58 rows=1,817 width=28) (actual rows= loops=)

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

WindowAgg (cost=208.69..254.12 rows=1,817 width=45) (actual rows= loops=)

149. 0.000 0.000 ↓ 0.0

Sort (cost=208.69..213.23 rows=1,817 width=29) (actual rows= loops=)

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

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

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

Hash (cost=42.45..42.45 rows=1,845 width=4) (actual rows= loops=)

152. 0.000 0.000 ↓ 0.0

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

153. 0.000 0.000 ↓ 0.0

Subquery Scan on *SELECT* 4 (cost=824.51..5,687.86 rows=31,495 width=44) (actual rows= loops=)

154. 0.000 0.000 ↓ 0.0

Hash Join (cost=824.51..5,372.91 rows=31,495 width=612) (actual rows= loops=)

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

Seq Scan on rates rates_3 (cost=0.00..3,583.15 rows=173,415 width=28) (actual rows= loops=)

156. 0.000 0.000 ↓ 0.0

Hash (cost=816.43..816.43 rows=646 width=24) (actual rows= loops=)

157. 0.000 0.000 ↓ 0.0

Hash Join (cost=518.54..816.43 rows=646 width=24) (actual rows= loops=)

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

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

159. 0.000 0.000 ↓ 0.0

Hash (cost=510.46..510.46 rows=646 width=24) (actual rows= loops=)

160. 0.000 0.000 ↓ 0.0

Hash Join (cost=419.98..510.46 rows=646 width=24) (actual rows= loops=)

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

WindowAgg (cost=245.39..305.51 rows=2,405 width=45) (actual rows= loops=)

162. 0.000 0.000 ↓ 0.0

Sort (cost=245.39..251.40 rows=2,405 width=29) (actual rows= loops=)

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

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

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

Hash (cost=155.19..155.19 rows=1,552 width=8) (actual rows= loops=)

165. 0.000 0.000 ↓ 0.0

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

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