explain.depesz.com

PostgreSQL's explain analyze made readable

Result: tRfz

Settings

Optimization(s) for this plan:

# exclusive inclusive rows x rows loops node
1. 7,550.625 46,957.221 ↓ 2.4 850,040 1

Merge Left Join (cost=3,112,263.76..3,120,879.31 rows=355,801 width=140) (actual time=36,350.801..46,957.221 rows=850,040 loops=1)

  • Merge 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))
  • Rows Removed by Join Filter: 43,703,359
2. 673.031 36,415.401 ↓ 2.4 850,040 1

Sort (cost=3,112,018.90..3,112,908.40 rows=355,801 width=176) (actual time=36,347.847..36,415.401 rows=850,040 loops=1)

  • Sort Key: projects.account_id, staff_memberships_1.currency
  • Sort Method: quicksort Memory: 214,596kB
3. 6,888.569 35,742.370 ↓ 2.4 850,040 1

Merge Left Join (cost=3,075,934.26..3,079,212.78 rows=355,801 width=176) (actual time=26,126.762..35,742.370 rows=850,040 loops=1)

  • Merge 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))
  • Rows Removed by Join Filter: 38,541,529
4. 624.797 26,191.496 ↓ 2.4 850,040 1

Sort (cost=3,075,689.39..3,076,578.90 rows=355,801 width=168) (actual time=26,125.086..26,191.496 rows=850,040 loops=1)

  • Sort Key: projects.account_id, ""*SELECT* 1"".currency
  • Sort Method: quicksort Memory: 189,324kB
5. 260.991 25,566.699 ↓ 2.4 850,040 1

Merge Left Join (cost=2,968,422.53..3,042,883.28 rows=355,801 width=168) (actual time=24,619.353..25,566.699 rows=850,040 loops=1)

  • 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))))
  • Rows Removed by Join Filter: 647,094
6. 463.470 25,263.631 ↓ 2.4 849,952 1

Merge Left Join (cost=2,968,399.76..3,025,639.72 rows=355,801 width=164) (actual time=24,618.621..25,263.631 rows=849,952 loops=1)

  • 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)))
  • Rows Removed by Join Filter: 229,908
7. 715.811 24,149.084 ↓ 2.4 849,952 1

Sort (cost=2,921,568.85..2,922,458.35 rows=355,801 width=136) (actual time=24,051.964..24,149.084 rows=849,952 loops=1)

  • Sort Key: projects.id, (COALESCE(""*SELECT* 1_1"".activity_id, staff_membership_activity_links.activity_id))
  • Sort Method: quicksort Memory: 144,101kB
8. 268.233 23,433.273 ↓ 2.4 849,952 1

Hash Join (cost=2,298,887.27..2,888,762.73 rows=355,801 width=136) (actual time=20,979.313..23,433.273 rows=849,952 loops=1)

  • Hash Cond: (projects.account_id = accounts.id)
9. 203.657 23,164.838 ↓ 1.5 1,614,425 1

Append (cost=2,298,868.60..2,875,234.54 rows=1,067,404 width=136) (actual time=20,979.068..23,164.838 rows=1,614,425 loops=1)

10. 707.138 22,663.310 ↓ 2.7 1,583,781 1

Hash Left Join (cost=2,298,868.60..2,342,459.08 rows=590,704 width=108) (actual time=20,979.068..22,663.310 rows=1,583,781 loops=1)

  • Hash Cond: (projects.account_id = accounts_1.id)
  • 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))
  • Rows Removed by Filter: 13,596
11. 731.949 21,956.016 ↑ 1.1 1,597,377 1

Merge Left Join (cost=2,298,849.64..2,315,603.07 rows=1,754,565 width=144) (actual time=20,978.896..21,956.016 rows=1,597,377 loops=1)

  • 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))))
  • Rows Removed by Join Filter: 258,899
12. 1,502.052 21,119.416 ↑ 1.1 1,597,377 1

Sort (cost=2,298,002.50..2,302,388.91 rows=1,754,565 width=120) (actual time=20,966.567..21,119.416 rows=1,597,377 loops=1)

  • Sort Key: projects.account_id, ""*SELECT* 1_1"".user_id
  • Sort Method: quicksort Memory: 268,517kB
13. 439.993 19,617.364 ↑ 1.1 1,597,377 1

Hash Left Join (cost=1,702,859.05..2,116,030.58 rows=1,754,565 width=120) (actual time=3,319.390..19,617.364 rows=1,597,377 loops=1)

  • Hash Cond: ("*SELECT* 1_1".project_id = projects.id)
14. 218.684 19,175.187 ↑ 1.1 1,597,377 1

Append (cost=1,702,630.28..2,093,647.07 rows=1,754,565 width=116) (actual time=3,317.173..19,175.187 rows=1,597,377 loops=1)

15. 298.769 4,994.119 ↑ 1.2 893,416 1

Result (cost=1,702,630.28..1,894,670.02 rows=1,050,604 width=116) (actual time=3,317.173..4,994.119 rows=893,416 loops=1)

16. 107.970 4,695.350 ↑ 1.2 893,416 1

Append (cost=1,702,630.28..1,881,537.47 rows=1,050,604 width=140) (actual time=3,317.168..4,695.350 rows=893,416 loops=1)

17. 125.708 3,920.634 ↑ 1.5 661,732 1

Subquery Scan on *SELECT* 1_1 (cost=1,702,630.28..1,745,963.69 rows=968,516 width=114) (actual time=3,317.167..3,920.634 rows=661,732 loops=1)

18. 179.456 3,794.926 ↑ 1.5 661,732 1

Merge Left Join (cost=1,702,630.28..1,731,435.95 rows=968,516 width=134) (actual time=3,317.165..3,794.926 rows=661,732 loops=1)

  • 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))
19. 209.861 3,467.165 ↑ 1.5 661,732 1

Merge Anti Join (cost=1,096,033.00..1,109,342.38 rows=968,516 width=66) (actual time=3,174.579..3,467.165 rows=661,732 loops=1)

  • 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))
20. 1,925.543 3,185.699 ↑ 1.8 669,378 1

Sort (cost=1,090,015.01..1,093,082.01 rows=1,226,800 width=66) (actual time=3,107.806..3,185.699 rows=669,378 loops=1)

  • Sort Key: projects_1.account_id, generate_series.generate_series, plan_rows.user_id
  • Sort Method: quicksort Memory: 118,708kB
21. 264.878 1,260.156 ↑ 1.8 669,378 1

Merge Left Join (cost=15,464.77..965,945.85 rows=1,226,800 width=66) (actual time=325.636..1,260.156 rows=669,378 loops=1)

  • 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))
  • Rows Removed by Join Filter: 328,283
22. 108.919 708.607 ↑ 1.8 669,378 1

Nested Loop (cost=6,506.23..943,392.38 rows=1,226,800 width=70) (actual time=90.746..708.607 rows=669,378 loops=1)

23. 26.462 169.596 ↑ 1.0 47,788 1

Merge Join (cost=6,506.22..11,024.38 rows=49,072 width=70) (actual time=90.708..169.596 rows=47,788 loops=1)

  • Merge Cond: (plan_rows.uuid = plan_items.plan_row_uuid)
24. 42.365 42.365 ↑ 1.0 42,344 1

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

  • Filter: (user_id IS NOT NULL)
  • Rows Removed by Filter: 5,762
25. 37.784 100.769 ↓ 1.0 55,664 1

Sort (cost=6,504.63..6,643.72 rows=55,639 width=58) (actual time=90.694..100.769 rows=55,664 loops=1)

  • Sort Key: plan_items.plan_row_uuid
  • Sort Method: quicksort Memory: 9,364kB
26. 11.871 62.985 ↓ 1.0 55,664 1

Hash Left Join (cost=430.80..2,119.21 rows=55,639 width=58) (actual time=7.932..62.985 rows=55,664 loops=1)

  • Hash Cond: (project_plans.project_id = projects_1.id)
27. 15.110 47.741 ↓ 1.0 55,664 1

Hash Left Join (cost=202.03..1,744.28 rows=55,639 width=54) (actual time=4.453..47.741 rows=55,664 loops=1)

  • Hash Cond: (plan_items.project_plan_id = project_plans.id)
28. 28.793 28.793 ↓ 1.0 55,664 1

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

  • Filter: (utilization > '0'::numeric)
  • Rows Removed by Filter: 264
29. 0.518 3.838 ↑ 1.0 2,851 1

Hash (cost=166.39..166.39 rows=2,851 width=8) (actual time=3.837..3.838 rows=2,851 loops=1)

  • Buckets: 4,096 Batches: 1 Memory Usage: 144kB
30. 3.320 3.320 ↑ 1.0 2,851 1

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

  • Filter: active
  • Rows Removed by Filter: 3,188
31. 0.968 3.373 ↑ 1.0 5,812 1

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

  • Buckets: 8,192 Batches: 1 Memory Usage: 292kB
32. 2.405 2.405 ↑ 1.0 5,812 1

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

33. 430.092 430.092 ↑ 1.8 14 47,788

Function Scan on generate_series (cost=0.01..18.76 rows=25 width=8) (actual time=0.004..0.009 rows=14 loops=47,788)

  • Filter: (date_part('dow'::text, generate_series) = ANY ('{1,2,3,4,5}'::double precision[]))
  • Rows Removed by Filter: 5
34. 75.907 286.671 ↓ 141.0 700,994 1

Sort (cost=8,958.54..8,970.97 rows=4,971 width=36) (actual time=234.881..286.671 rows=700,994 loops=1)

  • Sort Key: pa.plan_row_uuid
  • Sort Method: quicksort Memory: 5,007kB
35. 11.551 210.764 ↓ 8.9 44,428 1

Subquery Scan on pa (cost=8,529.07..8,653.34 rows=4,971 width=36) (actual time=145.465..210.764 rows=44,428 loops=1)

36. 81.344 199.213 ↓ 8.9 44,428 1

HashAggregate (cost=8,529.07..8,603.63 rows=4,971 width=48) (actual time=145.464..199.213 rows=44,428 loops=1)

  • 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)
37. 28.798 117.869 ↑ 1.0 44,581 1

WindowAgg (cost=6,077.00..7,080.12 rows=44,583 width=68) (actual time=83.583..117.869 rows=44,581 loops=1)

38. 26.068 89.071 ↑ 1.0 44,581 1

Sort (cost=6,077.00..6,188.46 rows=44,583 width=52) (actual time=83.556..89.071 rows=44,581 loops=1)

  • Sort Key: plan_roles.plan_row_uuid, plan_roles.start_date DESC NULLS LAST
  • Sort Method: quicksort Memory: 5,023kB
39. 17.102 63.003 ↑ 1.0 44,581 1

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

  • Hash Cond: (plan_roles.plan_row_uuid = plan_rows_1.uuid)
40. 14.982 14.982 ↑ 1.0 44,581 1

Seq Scan on plan_roles (cost=0.00..885.83 rows=44,583 width=24) (actual time=0.031..14.982 rows=44,581 loops=1)

41. 11.105 30.919 ↑ 1.0 48,106 1

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

  • Buckets: 65,536 Batches: 1 Memory Usage: 3,180kB
42. 19.814 19.814 ↑ 1.0 48,106 1

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

43. 40.224 71.605 ↑ 1.0 59,679 1

Sort (cost=6,017.99..6,167.27 rows=59,712 width=12) (actual time=66.764..71.605 rows=59,679 loops=1)

  • Sort Key: non_working_intervals_by_dates.account_id, non_working_intervals_by_dates.date, non_working_intervals_by_dates.user_id
  • Sort Method: quicksort Memory: 4,336kB
44. 31.381 31.381 ↑ 1.0 59,712 1

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

45. 40.911 148.305 ↑ 15.5 37,180 1

Sort (cost=606,597.28..608,034.78 rows=575,000 width=44) (actual time=142.577..148.305 rows=37,180 loops=1)

  • Sort Key: summary_vacations_by_dates.account_id, summary_vacations_by_dates.date, summary_vacations_by_dates.user_id
  • Sort Method: quicksort Memory: 2,844kB
46. 4.584 107.394 ↑ 17.8 32,266 1

Subquery Scan on summary_vacations_by_dates (cost=537,214.32..551,589.32 rows=575,000 width=44) (actual time=84.727..107.394 rows=32,266 loops=1)

47. 37.012 102.810 ↑ 17.8 32,266 1

HashAggregate (cost=537,214.32..545,839.32 rows=575,000 width=52) (actual time=84.726..102.810 rows=32,266 loops=1)

  • Group Key: generate_series_1.generate_series, staff_memberships.user_id, staff_memberships.account_id
48. 13.458 65.798 ↑ 134.2 32,422 1

Hash Join (cost=138.05..493,700.50 rows=4,351,382 width=21) (actual time=4.105..65.798 rows=32,422 loops=1)

  • 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)))
  • Rows Removed by Join Filter: 1,908
49. 17.704 48.322 ↑ 634.8 34,330 1

Nested Loop (cost=0.01..436,340.93 rows=21,792,000 width=17) (actual time=0.065..48.322 rows=34,330 loops=1)

50. 8.826 8.826 ↑ 1.0 21,792 1

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

51. 21.792 21.792 ↑ 500.0 2 21,792

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

52. 1.057 4.018 ↑ 1.0 4,002 1

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

  • Buckets: 4,096 Batches: 1 Memory Usage: 229kB
53. 2.961 2.961 ↑ 1.0 4,002 1

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

54. 167.128 666.746 ↓ 2.8 231,684 1

Hash Left Join (cost=2,062.19..129,499.88 rows=82,088 width=114) (actual time=23.218..666.746 rows=231,684 loops=1)

  • Hash Cond: (project_plans_1.project_id = projects_1_1.id)
  • Filter: (NOT (SubPlan 1))
  • Rows Removed by Filter: 770
55. 51.714 264.852 ↓ 1.4 232,454 1

Nested Loop (cost=1,833.42..128,165.83 rows=164,175 width=58) (actual time=20.856..264.852 rows=232,454 loops=1)

56. 2.751 55.618 ↓ 1.2 7,876 1

Hash Left Join (cost=1,833.41..3,392.83 rows=6,567 width=58) (actual time=20.829..55.618 rows=7,876 loops=1)

  • Hash Cond: (plan_items_1.project_plan_id = project_plans_1.id)
57. 20.531 51.254 ↓ 1.2 7,876 1

Hash Left Join (cost=1,631.38..3,173.55 rows=6,567 width=54) (actual time=19.189..51.254 rows=7,876 loops=1)

  • Hash Cond: (plan_items_1.plan_row_uuid = plan_rows_2.uuid)
  • Filter: (plan_rows_2.user_id IS NULL)
  • Rows Removed by Filter: 47,788
58. 11.635 11.635 ↓ 1.0 55,664 1

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

  • Filter: (utilization > '0'::numeric)
  • Rows Removed by Filter: 264
59. 10.635 19.088 ↑ 1.0 48,106 1

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

  • Buckets: 65,536 Batches: 1 Memory Usage: 3,117kB
60. 8.453 8.453 ↑ 1.0 48,106 1

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

61. 0.434 1.613 ↑ 1.0 2,851 1

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

  • Buckets: 4,096 Batches: 1 Memory Usage: 144kB
62. 1.179 1.179 ↑ 1.0 2,851 1

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

  • Filter: active
  • Rows Removed by Filter: 3,188
63. 157.520 157.520 ↓ 1.2 30 7,876

Function Scan on generate_series generate_series_2 (cost=0.01..18.76 rows=25 width=8) (actual time=0.007..0.020 rows=30 loops=7,876)

  • Filter: (date_part('dow'::text, generate_series) = ANY ('{1,2,3,4,5}'::double precision[]))
  • Rows Removed by Filter: 12
64. 1.096 2.312 ↑ 1.0 5,812 1

Hash (cost=156.12..156.12 rows=5,812 width=12) (actual time=2.311..2.312 rows=5,812 loops=1)

  • Buckets: 8,192 Batches: 1 Memory Usage: 314kB
65. 1.216 1.216 ↑ 1.0 5,812 1

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

66.          

SubPlan (for Hash Left Join)

67. 114.482 232.454 ↓ 0.0 0 232,454

Nested Loop (cost=0.69..16.74 rows=1 width=0) (actual time=0.001..0.001 rows=0 loops=232,454)

68. 0.000 0.000 ↓ 0.0 0 232,454

Index Scan using clients_pkey on clients clients_3 (cost=0.28..8.29 rows=1 width=4) (actual time=0.000..0.000 rows=0 loops=232,454)

  • Index Cond: (projects_1_1.client_id = id)
69. 117.972 117.972 ↓ 0.0 0 58,986

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 time=0.002..0.002 rows=0 loops=58,986)

  • Index Cond: ((account_id = projects_1_1.account_id) AND (office_id = clients_3.office_id) AND (date = generate_series_2.generate_series))
  • Heap Fetches: 770
70. 13,152.696 13,962.384 ↑ 1.0 703,961 1

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

  • 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))))
  • Rows Removed by Join Filter: 63,215,381
71. 108.364 204.585 ↓ 8.9 44,428 1

HashAggregate (cost=8,529.07..8,603.63 rows=4,971 width=48) (actual time=128.521..204.585 rows=44,428 loops=1)

  • 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)
72. 31.488 96.221 ↑ 1.0 44,581 1

WindowAgg (cost=6,077.00..7,080.12 rows=44,583 width=68) (actual time=58.550..96.221 rows=44,581 loops=1)

73. 25.633 64.733 ↑ 1.0 44,581 1

Sort (cost=6,077.00..6,188.46 rows=44,583 width=52) (actual time=58.523..64.733 rows=44,581 loops=1)

  • Sort Key: plan_roles_1.plan_row_uuid, plan_roles_1.start_date DESC NULLS LAST
  • Sort Method: quicksort Memory: 5,023kB
74. 16.870 39.100 ↑ 1.0 44,581 1

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

  • Hash Cond: (plan_roles_1.plan_row_uuid = plan_rows_3.uuid)
75. 4.364 4.364 ↑ 1.0 44,581 1

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

76. 9.965 17.866 ↑ 1.0 48,106 1

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

  • Buckets: 65,536 Batches: 1 Memory Usage: 3,180kB
77. 7.901 7.901 ↑ 1.0 48,106 1

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

78. 204.620 605.103 ↑ 1.0 703,961 1

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

  • Buckets: 1,048,576 Batches: 1 Memory Usage: 62,366kB
79. 258.783 400.483 ↑ 1.0 703,961 1

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

  • Hash Cond: (time_logs.epic_id = epics.id)
80. 110.329 110.329 ↑ 1.0 703,961 1

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

81. 5.889 31.371 ↑ 1.0 26,435 1

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

  • Buckets: 32,768 Batches: 1 Memory Usage: 1,381kB
82. 7.876 25.482 ↑ 1.0 26,435 1

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

  • Hash Cond: (epics.project_id = general_epic_plans.project_id)
  • Join Filter: (epics.project_plan_id IS NULL)
  • Rows Removed by Join Filter: 11,144
83. 15.834 15.834 ↑ 1.0 26,435 1

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

84. 0.547 1.772 ↑ 1.0 2,851 1

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

  • Buckets: 4,096 Batches: 1 Memory Usage: 144kB
85. 1.225 1.225 ↑ 1.0 2,851 1

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

  • Filter: active
  • Rows Removed by Filter: 3,188
86. 1.169 2.184 ↑ 1.0 5,812 1

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

  • Buckets: 8,192 Batches: 1 Memory Usage: 292kB
87. 1.015 1.015 ↑ 1.0 5,812 1

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

88. 90.269 104.651 ↓ 295.4 1,255,026 1

Materialize (cost=847.14..942.74 rows=4,249 width=40) (actual time=12.323..104.651 rows=1,255,026 loops=1)

89. 1.430 14.382 ↑ 1.0 4,218 1

Unique (cost=847.14..889.63 rows=4,249 width=65) (actual time=12.319..14.382 rows=4,218 loops=1)

90. 3.774 12.952 ↑ 1.0 4,246 1

Sort (cost=847.14..857.76 rows=4,249 width=65) (actual time=12.318..12.952 rows=4,246 loops=1)

  • 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
  • Sort Method: quicksort Memory: 790kB
91. 3.323 9.178 ↑ 1.0 4,249 1

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

92. 2.347 5.855 ↑ 1.0 4,249 1

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

  • Sort Key: staff_membership_activity_links.staff_membership_id, staff_membership_activity_links.start_date DESC NULLS LAST
  • Sort Method: quicksort Memory: 790kB
93. 1.545 3.508 ↑ 1.0 4,249 1

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

  • Hash Cond: (staff_membership_activity_links.staff_membership_id = staff_memberships_1.id)
94. 0.462 0.462 ↑ 1.0 4,256 1

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

95. 0.794 1.501 ↑ 1.0 4,002 1

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

  • Buckets: 4,096 Batches: 1 Memory Usage: 276kB
96. 0.707 0.707 ↑ 1.0 4,002 1

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

97. 0.057 0.156 ↑ 1.0 354 1

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

  • Buckets: 1,024 Batches: 1 Memory Usage: 24kB
98. 0.099 0.099 ↑ 1.0 354 1

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

99. 11.381 297.871 ↑ 15.6 30,644 1

Subquery Scan on *SELECT* 2_1 (cost=3,354.66..521,531.40 rows=476,700 width=136) (actual time=32.294..297.871 rows=30,644 loops=1)

100. 165.535 286.490 ↑ 15.6 30,644 1

Hash Anti Join (cost=3,354.66..515,572.65 rows=476,700 width=143) (actual time=32.292..286.490 rows=30,644 loops=1)

  • 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)
  • Rows Removed by Join Filter: 1,153,172
101. 22.996 101.514 ↑ 17.5 31,132 1

Merge Left Join (cost=1,177.86..481,269.67 rows=544,800 width=64) (actual time=12.583..101.514 rows=31,132 loops=1)

  • Merge Cond: (vacations_1.staff_membership_id = sa.staff_membership_id)
  • Join Filter: (((generate_series_3.generate_series)::date >= sa.start_date) AND ((generate_series_3.generate_series)::date <= sa.end_date))
  • Rows Removed by Join Filter: 10,924
102. 8.615 62.387 ↑ 17.5 31,132 1

Nested Loop (cost=0.29..415,689.39 rows=544,800 width=44) (actual time=0.041..62.387 rows=31,132 loops=1)

103. 10.188 10.188 ↑ 1.0 21,792 1

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 time=0.026..10.188 rows=21,792 loops=1)

104. 43.584 43.584 ↑ 25.0 1 21,792

Function Scan on generate_series generate_series_3 (cost=0.01..18.76 rows=25 width=8) (actual time=0.001..0.002 rows=1 loops=21,792)

  • Filter: (date_part('dow'::text, generate_series) = ANY ('{1,2,3,4,5}'::double precision[]))
  • Rows Removed by Filter: 0
105. 5.244 16.131 ↓ 10.2 43,399 1

Sort (cost=1,177.56..1,188.19 rows=4,249 width=36) (actual time=12.517..16.131 rows=43,399 loops=1)

  • Sort Key: sa.staff_membership_id
  • Sort Method: quicksort Memory: 522kB
106. 0.759 10.887 ↑ 1.0 4,221 1

Subquery Scan on sa (cost=836.52..921.50 rows=4,249 width=36) (actual time=9.090..10.887 rows=4,221 loops=1)

107. 0.739 10.128 ↑ 1.0 4,221 1

Unique (cost=836.52..879.01 rows=4,249 width=65) (actual time=9.088..10.128 rows=4,221 loops=1)

108. 2.319 9.389 ↑ 1.0 4,249 1

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

  • 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
  • Sort Method: quicksort Memory: 592kB
109. 2.286 7.070 ↑ 1.0 4,249 1

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

110. 1.726 4.784 ↑ 1.0 4,249 1

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

  • Sort Key: staff_membership_activity_links_1.staff_membership_id, staff_membership_activity_links_1.start_date DESC NULLS LAST
  • Sort Method: quicksort Memory: 561kB
111. 1.174 3.058 ↑ 1.0 4,249 1

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

  • Hash Cond: (staff_membership_activity_links_1.staff_membership_id = staff_memberships_2.id)
112. 0.332 0.332 ↑ 1.0 4,256 1

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

113. 0.823 1.552 ↑ 1.0 4,002 1

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

  • Buckets: 4,096 Batches: 1 Memory Usage: 245kB
114. 0.729 0.729 ↑ 1.0 4,002 1

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

115. 10.119 19.441 ↑ 1.0 58,975 1

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

  • Buckets: 65,536 Batches: 1 Memory Usage: 3,047kB
116. 9.322 9.322 ↑ 1.0 59,712 1

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 time=0.022..9.322 rows=59,712 loops=1)

117. 0.003 0.202 ↑ 9.8 12 1

Hash (cost=17.20..17.20 rows=118 width=4) (actual time=0.202..0.202 rows=12 loops=1)

  • Buckets: 1,024 Batches: 1 Memory Usage: 9kB
118. 0.199 0.199 ↑ 9.8 12 1

Seq Scan on accounts (cost=0.00..17.20 rows=118 width=4) (actual time=0.017..0.199 rows=12 loops=1)

  • Filter: ((suspended_at)::date >= CURRENT_DATE)
  • Rows Removed by Filter: 342
119. 361.931 651.077 ↓ 4.1 1,115,238 1

Sort (cost=46,830.92..47,512.59 rows=272,669 width=44) (actual time=566.636..651.077 rows=1,115,238 loops=1)

  • Sort Key: ""*SELECT* 1"".project_id, ""*SELECT* 1"".activity_id
  • Sort Method: quicksort Memory: 32,838kB
120. 30.138 289.146 ↑ 1.0 263,033 1

Append (cost=300.88..22,213.28 rows=272,669 width=44) (actual time=2.120..289.146 rows=263,033 loops=1)

121. 0.100 17.401 ↓ 9.7 474 1

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

122. 0.138 17.301 ↓ 9.7 474 1

Merge Join (cost=300.88..470.13 rows=49 width=612) (actual time=2.117..17.301 rows=474 loops=1)

  • Merge Cond: (clients.brand_id = brands.id)
123. 0.162 17.083 ↓ 9.7 474 1

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

124. 0.008 1.301 ↓ 5.0 5 1

Merge Join (cost=294.38..294.67 rows=1 width=32) (actual time=1.279..1.301 rows=5 loops=1)

  • Merge Cond: (rate_cards.rateable_id = clients.brand_id)
125. 0.025 0.599 ↑ 28.8 4 1

WindowAgg (cost=108.61..111.49 rows=115 width=45) (actual time=0.581..0.599 rows=4 loops=1)

126. 0.035 0.574 ↑ 23.0 5 1

Sort (cost=108.61..108.90 rows=115 width=29) (actual time=0.573..0.574 rows=5 loops=1)

  • Sort Key: rate_cards.rateable_id, rate_cards.start_date DESC NULLS LAST
  • Sort Method: quicksort Memory: 33kB
127. 0.539 0.539 ↑ 1.0 115 1

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

  • Filter: ((rateable_type)::text = 'Brand'::text)
  • Rows Removed by Filter: 4,739
128. 0.006 0.694 ↑ 1.0 5 1

Sort (cost=185.76..185.78 rows=5 width=8) (actual time=0.692..0.694 rows=5 loops=1)

  • Sort Key: clients.brand_id
  • Sort Method: quicksort Memory: 25kB
129. 0.007 0.688 ↑ 1.0 5 1

Nested Loop (cost=0.56..185.71 rows=5 width=8) (actual time=0.377..0.688 rows=5 loops=1)

130. 0.007 0.671 ↑ 1.0 5 1

Nested Loop (cost=0.28..184.13 rows=5 width=8) (actual time=0.370..0.671 rows=5 loops=1)

131. 0.649 0.649 ↑ 1.0 5 1

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

  • Filter: ((rates_type)::text = 'brand'::text)
  • Rows Removed by Filter: 5,805
132. 0.015 0.015 ↑ 1.0 1 5

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

  • Index Cond: (id = pricing_models.project_id)
133. 0.010 0.010 ↑ 1.0 1 5

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

  • Index Cond: (id = projects_2.client_id)
134. 15.620 15.620 ↓ 1.9 95 5

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 time=0.723..3.124 rows=95 loops=5)

  • Index Cond: (rate_card_id = rate_cards.id)
135. 0.054 0.080 ↑ 38.3 3 1

Sort (cost=6.09..6.37 rows=115 width=4) (actual time=0.079..0.080 rows=3 loops=1)

  • Sort Key: brands.id
  • Sort Method: quicksort Memory: 30kB
136. 0.026 0.026 ↑ 1.0 115 1

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

137. 13.510 78.457 ↓ 2.6 91,600 1

Subquery Scan on *SELECT* 2 (cost=583.00..5,484.31 rows=35,240 width=44) (actual time=15.231..78.457 rows=91,600 loops=1)

138. 39.308 64.947 ↓ 2.6 91,600 1

Hash Join (cost=583.00..5,131.91 rows=35,240 width=612) (actual time=15.230..64.947 rows=91,600 loops=1)

  • Hash Cond: (rates_1.rate_card_id = rate_cards_1.id)
139. 18.647 18.647 ↑ 1.0 174,437 1

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

140. 0.263 6.992 ↑ 1.1 657 1

Hash (cost=574.00..574.00 rows=720 width=24) (actual time=6.992..6.992 rows=657 loops=1)

  • Buckets: 1,024 Batches: 1 Memory Usage: 47kB
141. 0.895 6.729 ↑ 1.1 657 1

Hash Join (cost=378.98..574.00 rows=720 width=24) (actual time=4.224..6.729 rows=657 loops=1)

  • Hash Cond: (clients_1.office_id = offices.id)
142. 0.266 4.200 ↑ 1.0 623 1

Hash Join (cost=214.02..399.80 rows=623 width=8) (actual time=1.936..4.200 rows=623 loops=1)

  • Hash Cond: (projects_3.client_id = clients_1.id)
143. 1.219 3.309 ↑ 1.0 623 1

Hash Join (cost=150.41..334.56 rows=623 width=8) (actual time=1.292..3.309 rows=623 loops=1)

  • Hash Cond: (projects_3.id = pricing_models_1.project_id)
144. 0.822 0.822 ↑ 1.0 5,812 1

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

145. 0.160 1.268 ↑ 1.0 623 1

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

  • Buckets: 1,024 Batches: 1 Memory Usage: 30kB
146. 1.108 1.108 ↑ 1.0 623 1

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

  • Filter: ((rates_type)::text = 'office'::text)
  • Rows Removed by Filter: 5,187
147. 0.290 0.625 ↑ 1.0 1,849 1

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

  • Buckets: 2,048 Batches: 1 Memory Usage: 89kB
148. 0.335 0.335 ↑ 1.0 1,849 1

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

149. 0.120 1.634 ↑ 1.1 450 1

Hash (cost=158.85..158.85 rows=489 width=28) (actual time=1.633..1.634 rows=450 loops=1)

  • Buckets: 1,024 Batches: 1 Memory Usage: 35kB
150. 0.184 1.514 ↑ 1.1 450 1

Hash Join (cost=140.44..158.85 rows=489 width=28) (actual time=1.027..1.514 rows=450 loops=1)

  • Hash Cond: (rate_cards_1.rateable_id = offices.id)
151. 0.347 1.171 ↑ 1.0 489 1

WindowAgg (cost=126.52..138.74 rows=489 width=45) (actual time=0.794..1.171 rows=489 loops=1)

152. 0.249 0.824 ↑ 1.0 489 1

Sort (cost=126.52..127.74 rows=489 width=29) (actual time=0.786..0.824 rows=489 loops=1)

  • Sort Key: rate_cards_1.rateable_id, rate_cards_1.start_date DESC NULLS LAST
  • Sort Method: quicksort Memory: 63kB
153. 0.575 0.575 ↑ 1.0 489 1

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

  • Filter: ((rateable_type)::text = 'Office'::text)
  • Rows Removed by Filter: 4,365
154. 0.083 0.159 ↑ 1.0 441 1

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

  • Buckets: 1,024 Batches: 1 Memory Usage: 24kB
155. 0.076 0.076 ↑ 1.0 441 1

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

156. 14.473 88.494 ↑ 2.2 94,593 1

Subquery Scan on *SELECT* 3 (cost=840.78..9,363.71 rows=205,419 width=44) (actual time=14.988..88.494 rows=94,593 loops=1)

157. 40.804 74.021 ↑ 2.2 94,593 1

Hash Join (cost=840.78..7,309.52 rows=205,419 width=612) (actual time=14.987..74.021 rows=94,593 loops=1)

  • Hash Cond: (rates_2.rate_card_id = rate_cards_2.id)
158. 18.283 18.283 ↑ 1.0 174,437 1

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

159. 1.165 14.934 ↑ 1.0 4,004 1

Hash (cost=788.31..788.31 rows=4,197 width=24) (actual time=14.934..14.934 rows=4,004 loops=1)

  • Buckets: 8,192 Batches: 1 Memory Usage: 299kB
160. 1.169 13.769 ↑ 1.0 4,004 1

Hash Join (cost=586.95..788.31 rows=4,197 width=24) (actual time=10.256..13.769 rows=4,004 loops=1)

  • Hash Cond: (projects_4.client_id = clients_2.id)
161. 1.370 5.001 ↑ 1.0 3,620 1

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

  • Hash Cond: (pricing_models_2.project_id = projects_4.id)
162. 1.081 1.081 ↑ 1.0 3,621 1

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

  • Filter: ((rates_type)::text = 'client'::text)
  • Rows Removed by Filter: 2,189
163. 1.148 2.550 ↑ 1.0 5,812 1

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

  • Buckets: 8,192 Batches: 1 Memory Usage: 292kB
164. 1.402 1.402 ↑ 1.0 5,812 1

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

165. 0.627 7.599 ↑ 1.0 1,820 1

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

  • Buckets: 2,048 Batches: 1 Memory Usage: 123kB
166. 0.663 6.972 ↑ 1.0 1,820 1

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

  • Hash Cond: (rate_cards_2.rateable_id = clients_2.id)
167. 1.449 3.511 ↑ 1.0 1,821 1

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

168. 1.025 2.062 ↑ 1.0 1,821 1

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

  • Sort Key: rate_cards_2.rateable_id, rate_cards_2.start_date DESC NULLS LAST
  • Sort Method: quicksort Memory: 191kB
169. 1.037 1.037 ↑ 1.0 1,821 1

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

  • Filter: ((rateable_type)::text = 'Client'::text)
  • Rows Removed by Filter: 3,033
170. 2.504 2.798 ↑ 1.0 1,849 1

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

  • Buckets: 2,048 Batches: 1 Memory Usage: 82kB
171. 0.294 0.294 ↑ 1.0 1,849 1

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

172. 11.680 74.656 ↓ 2.4 76,366 1

Subquery Scan on *SELECT* 4 (cost=695.56..5,531.29 rows=31,961 width=44) (actual time=7.741..74.656 rows=76,366 loops=1)

173. 37.566 62.976 ↓ 2.4 76,366 1

Hash Join (cost=695.56..5,211.68 rows=31,961 width=612) (actual time=7.740..62.976 rows=76,366 loops=1)

  • Hash Cond: (rates_3.rate_card_id = rate_cards_3.id)
174. 17.723 17.723 ↑ 1.0 174,437 1

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

175. 0.449 7.687 ↓ 2.4 1,591 1

Hash (cost=687.40..687.40 rows=653 width=24) (actual time=7.686..7.687 rows=1,591 loops=1)

  • Buckets: 2,048 (originally 1024) Batches: 1 (originally 1) Memory Usage: 110kB
176. 1.023 7.238 ↓ 2.4 1,591 1

Hash Join (cost=502.95..687.40 rows=653 width=24) (actual time=5.654..7.238 rows=1,591 loops=1)

  • Hash Cond: (projects_5.id = pricing_models_3.project_id)
177. 0.607 0.607 ↑ 1.0 5,812 1

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

178. 0.403 5.608 ↓ 2.4 1,591 1

Hash (cost=494.79..494.79 rows=653 width=24) (actual time=5.608..5.608 rows=1,591 loops=1)

  • Buckets: 2,048 (originally 1024) Batches: 1 (originally 1) Memory Usage: 110kB
179. 0.535 5.205 ↓ 2.4 1,591 1

Hash Join (cost=403.40..494.79 rows=653 width=24) (actual time=2.895..5.205 rows=1,591 loops=1)

  • Hash Cond: (rate_cards_3.rateable_id = pricing_models_3.id)
180. 1.656 3.509 ↑ 1.0 2,429 1

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

181. 1.089 1.853 ↑ 1.0 2,429 1

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

  • Sort Key: rate_cards_3.rateable_id, rate_cards_3.start_date DESC NULLS LAST
  • Sort Method: quicksort Memory: 286kB
182. 0.764 0.764 ↑ 1.0 2,429 1

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

  • Filter: ((rateable_type)::text = 'PricingModel'::text)
  • Rows Removed by Filter: 2,425
183. 0.284 1.161 ↑ 1.0 1,561 1

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

  • Buckets: 2,048 Batches: 1 Memory Usage: 77kB
184. 0.877 0.877 ↑ 1.0 1,561 1

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

  • Filter: ((rates_type)::text = 'custom'::text)
  • Rows Removed by Filter: 4,249
185. 41.976 42.077 ↓ 2,151.2 658,252 1

Sort (cost=22.77..23.53 rows=306 width=26) (actual time=0.727..42.077 rows=658,252 loops=1)

  • Sort Key: discounts.project_id
  • Sort Method: quicksort Memory: 53kB
186. 0.101 0.101 ↓ 1.2 359 1

Seq Scan on discounts (cost=0.00..10.13 rows=306 width=26) (actual time=0.016..0.101 rows=359 loops=1)

  • Filter: (((discountable_type)::text = 'User'::text) OR ((discountable_type)::text = 'Epic'::text))
  • Rows Removed by Filter: 50
187. 2,661.813 2,662.305 ↓ 12,841.5 39,140,740 1

Sort (cost=244.86..252.48 rows=3,048 width=24) (actual time=1.553..2,662.305 rows=39,140,740 loops=1)

  • Sort Key: exchange_rates_by_months.account_id, exchange_rates_by_months.currency
  • Sort Method: quicksort Memory: 335kB
188. 0.492 0.492 ↑ 1.0 3,048 1

Seq Scan on exchange_rates_by_months (cost=0.00..68.48 rows=3,048 width=24) (actual time=0.015..0.492 rows=3,048 loops=1)

189. 2,990.514 2,991.195 ↓ 14,570.5 44,410,811 1

Sort (cost=244.86..252.48 rows=3,048 width=24) (actual time=2.815..2,991.195 rows=44,410,811 loops=1)

  • Sort Key: cost_exchange_rates.account_id, cost_exchange_rates.currency
  • Sort Method: quicksort Memory: 335kB
190. 0.681 0.681 ↑ 1.0 3,048 1

Seq Scan on exchange_rates_by_months cost_exchange_rates (cost=0.00..68.48 rows=3,048 width=24) (actual time=0.014..0.681 rows=3,048 loops=1)

Planning time : 23.963 ms
Execution time : 47,163.519 ms