explain.depesz.com

PostgreSQL's explain analyze made readable

Result: xnWY : Optimization for: plan #tRfz

Settings

Optimization path:

# exclusive inclusive rows x rows loops node
1. 7,580.223 46,958.376 ↓ 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,344.884..46,958.376 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: 43703359
2. 699.938 36,409.777 ↓ 2.4 850,040 1

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

  • Sort Key: projects.account_id, staff_memberships_1.currency
  • Sort Method: quicksort Memory: 214596kB
3. 6,805.972 35,709.839 ↓ 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,215.878..35,709.839 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: 38541529
4. 648.496 26,279.916 ↓ 2.4 850,040 1

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

  • Sort Key: projects.account_id, ""*SELECT* 1"".currency
  • Sort Method: quicksort Memory: 189324kB
5. 284.417 25,631.420 ↓ 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,604.969..25,631.420 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: 647094
6. 505.775 25,301.422 ↓ 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,604.798..25,301.422 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: 229908
7. 727.403 24,158.005 ↓ 2.4 849,952 1

Sort (cost=2,921,568.85..2,922,458.35 rows=355,801 width=136) (actual time=24,056.263..24,158.005 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: 144101kB
8. 272.248 23,430.602 ↓ 2.4 849,952 1

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

  • Hash Cond: (projects.account_id = accounts.id)
9. 199.632 23,158.232 ↓ 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,967.938..23,158.232 rows=1,614,425 loops=1)

10. 703.930 22,650.217 ↓ 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,967.937..22,650.217 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: 13596
11. 732.933 21,946.137 ↑ 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,967.773..21,946.137 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: 258899
12. 1,458.909 21,106.702 ↑ 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,954.860..21,106.702 rows=1,597,377 loops=1)

  • Sort Key: projects.account_id, ""*SELECT* 1_1"".user_id
  • Sort Method: quicksort Memory: 268517kB
13. 415.269 19,647.793 ↑ 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,613.033..19,647.793 rows=1,597,377 loops=1)

  • Hash Cond: ("*SELECT* 1_1".project_id = projects.id)
14. 202.377 19,230.670 ↑ 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,611.166..19,230.670 rows=1,597,377 loops=1)

15. 289.221 5,221.962 ↑ 1.2 893,416 1

Result (cost=1,702,630.28..1,894,670.02 rows=1,050,604 width=116) (actual time=3,611.166..5,221.962 rows=893,416 loops=1)

16. 104.223 4,932.741 ↑ 1.2 893,416 1

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

17. 123.299 4,189.900 ↑ 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,611.161..4,189.900 rows=661,732 loops=1)

18. 171.088 4,066.601 ↑ 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,611.159..4,066.601 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. 199.995 3,760.678 ↑ 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,481.749..3,760.678 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. 2,048.947 3,509.127 ↑ 1.8 669,378 1

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

  • Sort Key: projects_1.account_id, generate_series.generate_series, plan_rows.user_id
  • Sort Method: quicksort Memory: 118708kB
21. 324.845 1,460.180 ↑ 1.8 669,378 1

Merge Left Join (cost=15,464.77..965,945.85 rows=1,226,800 width=66) (actual time=298.714..1,460.180 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: 328283
22. 147.816 849.321 ↑ 1.8 669,378 1

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

23. 35.130 175.837 ↑ 1.0 47,788 1

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

  • Merge Cond: (plan_rows.uuid = plan_items.plan_row_uuid)
24. 54.217 54.217 ↑ 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.009..54.217 rows=42,344 loops=1)

  • Filter: (user_id IS NOT NULL)
  • Rows Removed by Filter: 5762
25. 42.688 86.490 ↓ 1.0 55,664 1

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

  • Sort Key: plan_items.plan_row_uuid
  • Sort Method: quicksort Memory: 9364kB
26. 12.714 43.802 ↓ 1.0 55,664 1

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

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

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

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

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

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

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

  • Buckets: 4096 Batches: 1 Memory Usage: 144kB
30. 1.205 1.205 ↑ 1.0 2,851 1

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

  • Filter: active
  • Rows Removed by Filter: 3188
31. 0.965 1.890 ↑ 1.0 5,812 1

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

  • Buckets: 8192 Batches: 1 Memory Usage: 292kB
32. 0.925 0.925 ↑ 1.0 5,812 1

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

33. 525.668 525.668 ↑ 1.8 14 47,788

Function Scan on generate_series (cost=0.01..18.76 rows=25 width=8) (actual time=0.004..0.011 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. 85.314 286.014 ↓ 141.0 700,994 1

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

  • Sort Key: pa.plan_row_uuid
  • Sort Method: quicksort Memory: 5007kB
35. 6.927 200.700 ↓ 8.9 44,428 1

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

36. 88.905 193.773 ↓ 8.9 44,428 1

HashAggregate (cost=8,529.07..8,603.63 rows=4,971 width=48) (actual time=139.228..193.773 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. 34.544 104.868 ↑ 1.0 44,581 1

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

38. 28.175 70.324 ↑ 1.0 44,581 1

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

  • Sort Key: plan_roles.plan_row_uuid, plan_roles.start_date DESC NULLS LAST
  • Sort Method: quicksort Memory: 5023kB
39. 16.793 42.149 ↑ 1.0 44,581 1

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

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

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

41. 11.611 20.851 ↑ 1.0 48,106 1

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

  • Buckets: 65536 Batches: 1 Memory Usage: 3180kB
42. 9.240 9.240 ↑ 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.006..9.240 rows=48,106 loops=1)

43. 39.801 51.556 ↑ 1.0 59,679 1

Sort (cost=6,017.99..6,167.27 rows=59,712 width=12) (actual time=47.373..51.556 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: 4336kB
44. 11.755 11.755 ↑ 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.014..11.755 rows=59,712 loops=1)

45. 41.614 134.835 ↑ 15.5 37,180 1

Sort (cost=606,597.28..608,034.78 rows=575,000 width=44) (actual time=129.403..134.835 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: 2844kB
46. 4.596 93.221 ↑ 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=70.256..93.221 rows=32,266 loops=1)

47. 36.269 88.625 ↑ 17.8 32,266 1

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

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

Hash Join (cost=138.05..493,700.50 rows=4,351,382 width=21) (actual time=1.683..52.356 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: 1908
49. 14.774 38.938 ↑ 634.8 34,330 1

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

50. 2.372 2.372 ↑ 1.0 21,792 1

Seq Scan on vacations (cost=0.00..500.92 rows=21,792 width=17) (actual time=0.015..2.372 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. 0.887 1.644 ↑ 1.0 4,002 1

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

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

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

54. 150.417 638.618 ↓ 2.8 231,684 1

Hash Left Join (cost=2,062.19..129,499.88 rows=82,088 width=114) (actual time=22.493..638.618 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. 50.049 253.138 ↓ 1.4 232,454 1

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

56. 2.593 53.445 ↓ 1.2 7,876 1

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

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

Hash Left Join (cost=1,631.38..3,173.55 rows=6,567 width=54) (actual time=18.135..49.186 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: 47788
58. 11.257 11.257 ↓ 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.015..11.257 rows=55,664 loops=1)

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

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

  • Buckets: 65536 Batches: 1 Memory Usage: 3117kB
60. 8.097 8.097 ↑ 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.097 rows=48,106 loops=1)

61. 0.477 1.666 ↑ 1.0 2,851 1

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

  • Buckets: 4096 Batches: 1 Memory Usage: 144kB
62. 1.189 1.189 ↑ 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.014..1.189 rows=2,851 loops=1)

  • Filter: active
  • Rows Removed by Filter: 3188
63. 149.644 149.644 ↓ 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.019 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.178 2.609 ↑ 1.0 5,812 1

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

  • Buckets: 8192 Batches: 1 Memory Usage: 314kB
65. 1.431 1.431 ↑ 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.009..1.431 rows=5,812 loops=1)

66.          

SubPlan (for Hash Left Join)

67. 173.468 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. 58.986 58.986 ↓ 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.001..0.001 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. 12,990.828 13,806.331 ↑ 1.0 703,961 1

Hash Right Join (cost=45,029.23..183,164.61 rows=703,961 width=116) (actual time=747.556..13,806.331 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: 63215381
71. 108.403 211.983 ↓ 8.9 44,428 1

HashAggregate (cost=8,529.07..8,603.63 rows=4,971 width=48) (actual time=139.195..211.983 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. 35.311 103.580 ↑ 1.0 44,581 1

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

73. 26.899 68.269 ↑ 1.0 44,581 1

Sort (cost=6,077.00..6,188.46 rows=44,583 width=52) (actual time=61.418..68.269 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: 5023kB
74. 18.417 41.370 ↑ 1.0 44,581 1

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

  • Hash Cond: (plan_roles_1.plan_row_uuid = plan_rows_3.uuid)
75. 4.618 4.618 ↑ 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.010..4.618 rows=44,581 loops=1)

76. 10.281 18.335 ↑ 1.0 48,106 1

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

  • Buckets: 65536 Batches: 1 Memory Usage: 3180kB
77. 8.054 8.054 ↑ 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..8.054 rows=48,106 loops=1)

78. 207.296 603.520 ↑ 1.0 703,961 1

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

  • Buckets: 1048576 Batches: 1 Memory Usage: 62366kB
79. 262.792 396.224 ↑ 1.0 703,961 1

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

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

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

81. 4.435 14.989 ↑ 1.0 26,435 1

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

  • Buckets: 32768 Batches: 1 Memory Usage: 1381kB
82. 6.374 10.554 ↑ 1.0 26,435 1

Hash Left Join (cost=202.03..1,496.14 rows=26,435 width=16) (actual time=1.989..10.554 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: 11144
83. 2.274 2.274 ↑ 1.0 26,435 1

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

84. 0.594 1.906 ↑ 1.0 2,851 1

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

  • Buckets: 4096 Batches: 1 Memory Usage: 144kB
85. 1.312 1.312 ↑ 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.019..1.312 rows=2,851 loops=1)

  • Filter: active
  • Rows Removed by Filter: 3188
86. 0.998 1.854 ↑ 1.0 5,812 1

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

  • Buckets: 8192 Batches: 1 Memory Usage: 292kB
87. 0.856 0.856 ↑ 1.0 5,812 1

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

88. 91.513 106.502 ↓ 295.4 1,255,026 1

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

89. 1.502 14.989 ↑ 1.0 4,218 1

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

90. 3.318 13.487 ↑ 1.0 4,246 1

Sort (cost=847.14..857.76 rows=4,249 width=65) (actual time=12.904..13.487 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.353 10.169 ↑ 1.0 4,249 1

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

92. 2.649 6.816 ↑ 1.0 4,249 1

Sort (cost=484.85..495.47 rows=4,249 width=56) (actual time=6.451..6.816 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.509 4.167 ↑ 1.0 4,249 1

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

  • Hash Cond: (staff_membership_activity_links.staff_membership_id = staff_memberships_1.id)
94. 0.421 0.421 ↑ 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.014..0.421 rows=4,256 loops=1)

95. 1.198 2.237 ↑ 1.0 4,002 1

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

  • Buckets: 4096 Batches: 1 Memory Usage: 276kB
96. 1.039 1.039 ↑ 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.006..1.039 rows=4,002 loops=1)

97. 0.061 0.150 ↑ 1.0 354 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 24kB
98. 0.089 0.089 ↑ 1.0 354 1

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

99. 12.110 308.383 ↑ 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=36.231..308.383 rows=30,644 loops=1)

100. 167.523 296.273 ↑ 15.6 30,644 1

Hash Anti Join (cost=3,354.66..515,572.65 rows=476,700 width=143) (actual time=36.229..296.273 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: 1153172
101. 23.651 106.889 ↑ 17.5 31,132 1

Merge Left Join (cost=1,177.86..481,269.67 rows=544,800 width=64) (actual time=14.333..106.889 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: 10924
102. 10.623 65.331 ↑ 17.5 31,132 1

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

103. 11.124 11.124 ↑ 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.027..11.124 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.101 17.907 ↓ 10.2 43,399 1

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

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

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

107. 0.776 12.012 ↑ 1.0 4,221 1

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

108. 2.865 11.236 ↑ 1.0 4,249 1

Sort (cost=836.52..847.14 rows=4,249 width=65) (actual time=10.965..11.236 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.797 8.371 ↑ 1.0 4,249 1

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

110. 1.967 5.574 ↑ 1.0 4,249 1

Sort (cost=484.85..495.47 rows=4,249 width=44) (actual time=5.296..5.574 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.309 3.607 ↑ 1.0 4,249 1

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

  • Hash Cond: (staff_membership_activity_links_1.staff_membership_id = staff_memberships_2.id)
112. 0.417 0.417 ↑ 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.033..0.417 rows=4,256 loops=1)

113. 1.035 1.881 ↑ 1.0 4,002 1

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

  • Buckets: 4096 Batches: 1 Memory Usage: 245kB
114. 0.846 0.846 ↑ 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.007..0.846 rows=4,002 loops=1)

115. 11.366 21.861 ↑ 1.0 58,975 1

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

  • Buckets: 65536 Batches: 1 Memory Usage: 3047kB
116. 10.495 10.495 ↑ 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.011..10.495 rows=59,712 loops=1)

117. 0.004 0.122 ↑ 9.8 12 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
118. 0.118 0.118 ↑ 9.8 12 1

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

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

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

  • Sort Key: ""*SELECT* 1"".project_id, ""*SELECT* 1"".activity_id
  • Sort Method: quicksort Memory: 32838kB
120. 30.940 278.349 ↑ 1.0 263,033 1

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

121. 0.095 16.469 ↓ 9.7 474 1

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

122. 0.145 16.374 ↓ 9.7 474 1

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

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

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

124. 0.010 1.734 ↓ 5.0 5 1

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

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

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

126. 0.077 0.634 ↑ 23.0 5 1

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

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

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

  • Filter: ((rateable_type)::text = 'Brand'::text)
  • Rows Removed by Filter: 4739
128. 0.034 1.059 ↑ 1.0 5 1

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

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

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

130. 0.012 1.000 ↑ 1.0 5 1

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

131. 0.968 0.968 ↑ 1.0 5 1

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

  • Filter: ((rates_type)::text = 'brand'::text)
  • Rows Removed by Filter: 5805
132. 0.020 0.020 ↑ 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.004..0.004 rows=1 loops=5)

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

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

  • Index Cond: (id = projects_2.client_id)
134. 14.220 14.220 ↓ 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.668..2.844 rows=95 loops=5)

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

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

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

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

137. 14.355 77.811 ↓ 2.6 91,600 1

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

138. 40.448 63.456 ↓ 2.6 91,600 1

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

  • Hash Cond: (rates_1.rate_card_id = rate_cards_1.id)
139. 18.205 18.205 ↑ 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.010..18.205 rows=174,437 loops=1)

140. 0.160 4.803 ↑ 1.1 657 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 47kB
141. 0.179 4.643 ↑ 1.1 657 1

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

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

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

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

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

  • Hash Cond: (projects_3.id = pricing_models_1.project_id)
144. 0.542 0.542 ↑ 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.542 rows=5,812 loops=1)

145. 0.099 0.813 ↑ 1.0 623 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 30kB
146. 0.714 0.714 ↑ 1.0 623 1

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

  • Filter: ((rates_type)::text = 'office'::text)
  • Rows Removed by Filter: 5187
147. 0.360 0.717 ↑ 1.0 1,849 1

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

  • Buckets: 2048 Batches: 1 Memory Usage: 89kB
148. 0.357 0.357 ↑ 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.357 rows=1,849 loops=1)

149. 0.115 1.434 ↑ 1.1 450 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 35kB
150. 0.106 1.319 ↑ 1.1 450 1

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

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

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

152. 0.215 0.784 ↑ 1.0 489 1

Sort (cost=126.52..127.74 rows=489 width=29) (actual time=0.741..0.784 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.569 0.569 ↑ 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.569 rows=489 loops=1)

  • Filter: ((rateable_type)::text = 'Office'::text)
  • Rows Removed by Filter: 4365
154. 0.077 0.141 ↑ 1.0 441 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 24kB
155. 0.064 0.064 ↑ 1.0 441 1

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

156. 14.634 82.874 ↑ 2.2 94,593 1

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

157. 41.151 68.240 ↑ 2.2 94,593 1

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

  • Hash Cond: (rates_2.rate_card_id = rate_cards_2.id)
158. 17.654 17.654 ↑ 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.009..17.654 rows=174,437 loops=1)

159. 0.819 9.435 ↑ 1.0 4,004 1

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

  • Buckets: 8192 Batches: 1 Memory Usage: 299kB
160. 0.919 8.616 ↑ 1.0 4,004 1

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

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

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

  • Hash Cond: (pricing_models_2.project_id = projects_4.id)
162. 0.855 0.855 ↑ 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.006..0.855 rows=3,621 loops=1)

  • Filter: ((rates_type)::text = 'client'::text)
  • Rows Removed by Filter: 2189
163. 0.901 2.022 ↑ 1.0 5,812 1

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

  • Buckets: 8192 Batches: 1 Memory Usage: 292kB
164. 1.121 1.121 ↑ 1.0 5,812 1

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

165. 0.387 3.843 ↑ 1.0 1,820 1

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

  • Buckets: 2048 Batches: 1 Memory Usage: 123kB
166. 0.377 3.456 ↑ 1.0 1,820 1

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

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

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

168. 0.804 1.529 ↑ 1.0 1,821 1

Sort (cost=203.29..207.84 rows=1,821 width=29) (actual time=1.417..1.529 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. 0.725 0.725 ↑ 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.007..0.725 rows=1,821 loops=1)

  • Filter: ((rateable_type)::text = 'Client'::text)
  • Rows Removed by Filter: 3033
170. 0.278 0.501 ↑ 1.0 1,849 1

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

  • Buckets: 2048 Batches: 1 Memory Usage: 82kB
171. 0.223 0.223 ↑ 1.0 1,849 1

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

172. 11.211 70.255 ↓ 2.4 76,366 1

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

173. 35.736 59.044 ↓ 2.4 76,366 1

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

  • Hash Cond: (rates_3.rate_card_id = rate_cards_3.id)
174. 16.341 16.341 ↑ 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.009..16.341 rows=174,437 loops=1)

175. 0.405 6.967 ↓ 2.4 1,591 1

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

  • Buckets: 2048 (originally 1024) Batches: 1 (originally 1) Memory Usage: 110kB
176. 0.954 6.562 ↓ 2.4 1,591 1

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

  • Hash Cond: (projects_5.id = pricing_models_3.project_id)
177. 0.582 0.582 ↑ 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.582 rows=5,812 loops=1)

178. 0.341 5.026 ↓ 2.4 1,591 1

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

  • Buckets: 2048 (originally 1024) Batches: 1 (originally 1) Memory Usage: 110kB
179. 0.462 4.685 ↓ 2.4 1,591 1

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

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

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

181. 0.978 1.658 ↑ 1.0 2,429 1

Sort (cost=241.26..247.33 rows=2,429 width=29) (actual time=1.498..1.658 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.680 0.680 ↑ 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.009..0.680 rows=2,429 loops=1)

  • Filter: ((rateable_type)::text = 'PricingModel'::text)
  • Rows Removed by Filter: 2425
183. 0.263 1.055 ↑ 1.0 1,561 1

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

  • Buckets: 2048 Batches: 1 Memory Usage: 77kB
184. 0.792 0.792 ↑ 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.008..0.792 rows=1,561 loops=1)

  • Filter: ((rates_type)::text = 'custom'::text)
  • Rows Removed by Filter: 4249
185. 45.493 45.581 ↓ 2,151.2 658,252 1

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

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

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

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

Sort (cost=244.86..252.48 rows=3,048 width=24) (actual time=1.941..2,623.951 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.752 0.752 ↑ 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.016..0.752 rows=3,048 loops=1)

189. 2,967.757 2,968.376 ↓ 14,570.5 44,410,811 1

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

  • Sort Key: cost_exchange_rates.account_id, cost_exchange_rates.currency
  • Sort Method: quicksort Memory: 335kB
190. 0.619 0.619 ↑ 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.016..0.619 rows=3,048 loops=1)

Planning time : 12.671 ms
Execution time : 47,202.480 ms