explain.depesz.com

PostgreSQL's explain analyze made readable

Result: RBKQ

Settings
# exclusive inclusive rows x rows loops node
1. 10,844.226 63,586.765 ↓ 2.4 850,040 1

Merge Left Join (cost=3,112,263.76..3,120,879.31 rows=355,801 width=140) (actual time=48,379.198..63,586.765 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. 982.823 48,468.569 ↓ 2.4 850,040 1

Sort (cost=3,112,018.90..3,112,908.40 rows=355,801 width=176) (actual time=48,376.835..48,468.569 rows=850,040 loops=1)

  • Sort Key: projects.account_id, staff_memberships_1.currency
  • Sort Method: quicksort Memory: 214596kB
3. 9,748.684 47,485.746 ↓ 2.4 850,040 1

Merge Left Join (cost=3,075,934.26..3,079,212.78 rows=355,801 width=176) (actual time=33,871.646..47,485.746 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. 857.587 33,960.909 ↓ 2.4 850,040 1

Sort (cost=3,075,689.39..3,076,578.90 rows=355,801 width=168) (actual time=33,869.511..33,960.909 rows=850,040 loops=1)

  • Sort Key: projects.account_id, ""*SELECT* 1"".currency
  • Sort Method: quicksort Memory: 189324kB
5. 384.328 33,103.322 ↓ 2.4 850,040 1

Merge Left Join (cost=2,968,422.53..3,042,883.28 rows=355,801 width=168) (actual time=31,745.254..33,103.322 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. 668.806 32,654.826 ↓ 2.4 849,952 1

Merge Left Join (cost=2,968,399.76..3,025,639.72 rows=355,801 width=164) (actual time=31,744.898..32,654.826 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. 929.482 31,065.844 ↓ 2.4 849,952 1

Sort (cost=2,921,568.85..2,922,458.35 rows=355,801 width=136) (actual time=30,941.380..31,065.844 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. 373.704 30,136.362 ↓ 2.4 849,952 1

Hash Join (cost=2,298,887.27..2,888,762.73 rows=355,801 width=136) (actual time=26,763.315..30,136.362 rows=849,952 loops=1)

  • Hash Cond: (projects.account_id = accounts.id)
9. 282.274 29,762.538 ↓ 1.5 1,614,425 1

Append (cost=2,298,868.60..2,875,234.54 rows=1,067,404 width=136) (actual time=26,763.170..29,762.538 rows=1,614,425 loops=1)

10. 972.233 29,061.391 ↓ 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=26,763.169..29,061.391 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. 999.714 28,088.956 ↑ 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=26,762.952..28,088.956 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,964.144 26,943.363 ↑ 1.1 1,597,377 1

Sort (cost=2,298,002.50..2,302,388.91 rows=1,754,565 width=120) (actual time=26,744.479..26,943.363 rows=1,597,377 loops=1)

  • Sort Key: projects.account_id, ""*SELECT* 1_1"".user_id
  • Sort Method: quicksort Memory: 268517kB
13. 578.548 24,979.219 ↑ 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=4,560.502..24,979.219 rows=1,597,377 loops=1)

  • Hash Cond: ("*SELECT* 1_1".project_id = projects.id)
14. 287.566 24,397.797 ↑ 1.1 1,597,377 1

Append (cost=1,702,630.28..2,093,647.07 rows=1,754,565 width=116) (actual time=4,557.598..24,397.797 rows=1,597,377 loops=1)

15. 406.761 6,799.159 ↑ 1.2 893,416 1

Result (cost=1,702,630.28..1,894,670.02 rows=1,050,604 width=116) (actual time=4,557.598..6,799.159 rows=893,416 loops=1)

16. 146.067 6,392.398 ↑ 1.2 893,416 1

Append (cost=1,702,630.28..1,881,537.47 rows=1,050,604 width=140) (actual time=4,557.591..6,392.398 rows=893,416 loops=1)

17. 170.493 5,363.635 ↑ 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=4,557.590..5,363.635 rows=661,732 loops=1)

18. 242.624 5,193.142 ↑ 1.5 661,732 1

Merge Left Join (cost=1,702,630.28..1,731,435.95 rows=968,516 width=134) (actual time=4,557.586..5,193.142 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. 281.793 4,757.588 ↑ 1.5 661,732 1

Merge Anti Join (cost=1,096,033.00..1,109,342.38 rows=968,516 width=66) (actual time=4,371.677..4,757.588 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,705.439 4,411.690 ↑ 1.8 669,378 1

Sort (cost=1,090,015.01..1,093,082.01 rows=1,226,800 width=66) (actual time=4,314.090..4,411.690 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. 383.821 1,706.251 ↑ 1.8 669,378 1

Merge Left Join (cost=15,464.77..965,945.85 rows=1,226,800 width=66) (actual time=371.759..1,706.251 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. 157.446 976.544 ↑ 1.8 669,378 1

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

23. 36.660 197.854 ↑ 1.0 47,788 1

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

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

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

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

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

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

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

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

  • Hash Cond: (plan_items.project_plan_id = project_plans.id)
28. 15.366 15.366 ↓ 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..15.366 rows=55,664 loops=1)

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

Hash (cost=166.39..166.39 rows=2,851 width=8) (actual time=1.620..1.620 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.944 1.855 ↑ 1.0 5,812 1

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

  • Buckets: 8192 Batches: 1 Memory Usage: 292kB
32. 0.911 0.911 ↑ 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.911 rows=5,812 loops=1)

33. 621.244 621.244 ↑ 1.8 14 47,788

Function Scan on generate_series (cost=0.01..18.76 rows=25 width=8) (actual time=0.005..0.013 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. 101.538 345.886 ↓ 141.0 700,994 1

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

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

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

36. 101.228 237.247 ↓ 8.9 44,428 1

HashAggregate (cost=8,529.07..8,603.63 rows=4,971 width=48) (actual time=174.635..237.247 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. 38.968 136.019 ↑ 1.0 44,581 1

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

38. 37.514 97.051 ↑ 1.0 44,581 1

Sort (cost=6,077.00..6,188.46 rows=44,583 width=52) (actual time=90.010..97.051 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. 23.566 59.537 ↑ 1.0 44,581 1

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

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

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

41. 16.229 29.353 ↑ 1.0 48,106 1

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

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

43. 49.312 64.105 ↑ 1.0 59,679 1

Sort (cost=6,017.99..6,167.27 rows=59,712 width=12) (actual time=57.579..64.105 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. 14.793 14.793 ↑ 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.021..14.793 rows=59,712 loops=1)

45. 62.385 192.930 ↑ 15.5 37,180 1

Sort (cost=606,597.28..608,034.78 rows=575,000 width=44) (actual time=185.899..192.930 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. 7.060 130.545 ↑ 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=98.189..130.545 rows=32,266 loops=1)

47. 47.853 123.485 ↑ 17.8 32,266 1

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

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

Hash Join (cost=138.05..493,700.50 rows=4,351,382 width=21) (actual time=1.533..75.632 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. 9.753 56.851 ↑ 634.8 34,330 1

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

50. 3.514 3.514 ↑ 1.0 21,792 1

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

51. 43.584 43.584 ↑ 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.002 rows=2 loops=21,792)

52. 0.767 1.499 ↑ 1.0 4,002 1

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

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

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

54. 60.031 882.696 ↓ 2.8 231,684 1

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

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

56. 3.611 75.322 ↓ 1.2 7,876 1

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

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

Hash Left Join (cost=1,631.38..3,173.55 rows=6,567 width=54) (actual time=27.362..69.236 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. 15.463 15.463 ↓ 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.022..15.463 rows=55,664 loops=1)

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

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

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

61. 0.735 2.475 ↑ 1.0 2,851 1

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

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

  • Filter: active
  • Rows Removed by Filter: 3188
63. 212.652 212.652 ↓ 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.010..0.027 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.421 2.993 ↑ 1.0 5,812 1

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

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

66.          

SubPlan (for Hash Left Join)

67. 114.482 464.908 ↓ 0.0 0 232,454

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

68. 232.454 232.454 ↓ 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.001..0.001 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. 16,219.174 17,311.072 ↑ 1.0 703,961 1

Hash Right Join (cost=45,029.23..183,164.61 rows=703,961 width=116) (actual time=1,009.457..17,311.072 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. 130.203 270.806 ↓ 8.9 44,428 1

HashAggregate (cost=8,529.07..8,603.63 rows=4,971 width=48) (actual time=182.528..270.806 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. 42.614 140.603 ↑ 1.0 44,581 1

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

73. 38.166 97.989 ↑ 1.0 44,581 1

Sort (cost=6,077.00..6,188.46 rows=44,583 width=52) (actual time=90.714..97.989 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. 23.303 59.823 ↑ 1.0 44,581 1

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

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

76. 16.498 29.900 ↑ 1.0 48,106 1

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

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

78. 290.686 821.092 ↑ 1.0 703,961 1

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

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

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

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

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

81. 8.585 27.386 ↑ 1.0 26,435 1

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

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

Hash Left Join (cost=202.03..1,496.14 rows=26,435 width=16) (actual time=2.613..18.801 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. 4.054 4.054 ↑ 1.0 26,435 1

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

84. 0.804 2.548 ↑ 1.0 2,851 1

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

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

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

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

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

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

88. 124.913 145.879 ↓ 295.4 1,255,026 1

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

89. 1.770 20.966 ↑ 1.0 4,218 1

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

90. 5.125 19.196 ↑ 1.0 4,246 1

Sort (cost=847.14..857.76 rows=4,249 width=65) (actual time=18.460..19.196 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. 4.869 14.071 ↑ 1.0 4,249 1

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

92. 3.316 9.202 ↑ 1.0 4,249 1

Sort (cost=484.85..495.47 rows=4,249 width=56) (actual time=8.696..9.202 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. 2.332 5.886 ↑ 1.0 4,249 1

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

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

95. 1.597 2.915 ↑ 1.0 4,002 1

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

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

97. 0.085 0.202 ↑ 1.0 354 1

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

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

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

99. 15.637 418.873 ↑ 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=56.004..418.873 rows=30,644 loops=1)

100. 224.145 403.236 ↑ 15.6 30,644 1

Hash Anti Join (cost=3,354.66..515,572.65 rows=476,700 width=143) (actual time=56.000..403.236 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. 31.817 145.338 ↑ 17.5 31,132 1

Merge Left Join (cost=1,177.86..481,269.67 rows=544,800 width=64) (actual time=21.831..145.338 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. 28.474 86.651 ↑ 17.5 31,132 1

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

103. 14.593 14.593 ↑ 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.020..14.593 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.002..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. 7.785 26.870 ↓ 10.2 43,399 1

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

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

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

107. 1.397 17.699 ↑ 1.0 4,221 1

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

108. 3.956 16.302 ↑ 1.0 4,249 1

Sort (cost=836.52..847.14 rows=4,249 width=65) (actual time=15.829..16.302 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. 3.798 12.346 ↑ 1.0 4,249 1

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

110. 2.991 8.548 ↑ 1.0 4,249 1

Sort (cost=484.85..495.47 rows=4,249 width=44) (actual time=8.090..8.548 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. 2.186 5.557 ↑ 1.0 4,249 1

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

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

113. 1.449 2.745 ↑ 1.0 4,002 1

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

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

115. 17.642 33.753 ↑ 1.0 58,975 1

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

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

117. 0.003 0.120 ↑ 9.8 12 1

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

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

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

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

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

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

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

121. 0.128 19.365 ↓ 9.7 474 1

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

122. 0.151 19.237 ↓ 9.7 474 1

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

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

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

124. 0.009 1.935 ↓ 5.0 5 1

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

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

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

126. 0.052 0.837 ↑ 23.0 5 1

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

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

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

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

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

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

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

130. 0.011 1.029 ↑ 1.0 5 1

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

131. 0.998 0.998 ↑ 1.0 5 1

Seq Scan on pricing_models (cost=0.00..142.62 rows=5 width=4) (actual time=0.524..0.998 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.015 0.015 ↑ 1.0 1 5

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

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

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

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

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

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

137. 20.414 106.576 ↓ 2.6 91,600 1

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

138. 55.422 86.162 ↓ 2.6 91,600 1

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

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

140. 0.259 7.076 ↑ 1.1 657 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 47kB
141. 0.267 6.817 ↑ 1.1 657 1

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

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

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

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

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

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

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

145. 0.160 1.272 ↑ 1.0 623 1

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

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

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

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

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

  • Buckets: 2048 Batches: 1 Memory Usage: 89kB
148. 0.440 0.440 ↑ 1.0 1,849 1

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

149. 0.183 1.980 ↑ 1.1 450 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 35kB
150. 0.163 1.797 ↑ 1.1 450 1

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

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

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

152. 0.250 0.961 ↑ 1.0 489 1

Sort (cost=126.52..127.74 rows=489 width=29) (actual time=0.914..0.961 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.711 0.711 ↑ 1.0 489 1

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

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

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

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

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

156. 20.486 120.711 ↑ 2.2 94,593 1

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

157. 58.787 100.225 ↑ 2.2 94,593 1

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

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

159. 1.445 16.312 ↑ 1.0 4,004 1

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

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

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

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

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

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

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

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

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

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

165. 0.741 6.517 ↑ 1.0 1,820 1

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

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

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

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

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

168. 1.114 2.207 ↑ 1.0 1,821 1

Sort (cost=203.29..207.84 rows=1,821 width=29) (actual time=1.983..2.207 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.093 1.093 ↑ 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.010..1.093 rows=1,821 loops=1)

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

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

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

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

172. 17.192 106.130 ↓ 2.4 76,366 1

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

173. 53.266 88.938 ↓ 2.4 76,366 1

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

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

175. 0.666 11.552 ↓ 2.4 1,591 1

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

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

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

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

178. 0.591 8.329 ↓ 2.4 1,591 1

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

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

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

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

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

181. 1.616 2.779 ↑ 1.0 2,429 1

Sort (cost=241.26..247.33 rows=2,429 width=29) (actual time=2.503..2.779 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. 1.163 1.163 ↑ 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..1.163 rows=2,429 loops=1)

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

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

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

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

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

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

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

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

Sort (cost=244.86..252.48 rows=3,048 width=24) (actual time=2.038..3,776.153 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.764 0.764 ↑ 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.021..0.764 rows=3,048 loops=1)

189. 4,273.252 4,273.970 ↓ 14,570.5 44,410,811 1

Sort (cost=244.86..252.48 rows=3,048 width=24) (actual time=2.131..4,273.970 rows=44,410,811 loops=1)

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

Planning time : 8.232 ms
Execution time : 63,837.644 ms