QUERY PLAN
Hash Left Join (cost=1521.56..116925079.13 rows=4663950000 width=532)
Hash Cond: (c.id = tmp9.client_id)
-> Hash Left Join (cost=1014.65..5175.66 rows=23319750 width=467)
Hash Cond: (c.id = tmp8.client_id)
-> Hash Left Join (cost=737.47..2829.79 rows=150450 width=435)
Hash Cond: (c.id = tmp7.client_id)
-> Hash Left Join (cost=91.62..1149.60 rows=75225 width=411)
Hash Cond: (c.client_industry = ci.id)
-> Nested Loop Left Join (cost=90.06..918.20 rows=75225 width=265)
Join Filter: (tmp5.client_id = c.id)
-> Nested Loop Left Join (cost=90.06..540.23 rows=425 width=241)
Join Filter: (tmp1.client_id = c.id)
-> Nested Loop Left Join (cost=85.43..436.26 rows=17 width=165)
Join Filter: (ps.client_id = c.id)
-> Nested Loop Left Join (cost=85.43..343.35 rows=1 width=141)
Join Filter: (p_1.client_id = c.id)
-> Nested Loop Left Join (cost=80.80..241.02 rows=1 width=101)
Join Filter: (p.client_id = c.id)
-> Nested Loop Left Join (cost=76.18..138.69 rows=1 width=61)
Join Filter: ((csrr.client_id = c.id) AND (csrr.sales_rep = c.sales_rep))
-> Index Scan using tbl_clients_pkey on tbl_clients c (cost=0.28..8.29 rows=1 width=65)
Index Cond: (id = 149)
-> Hash Join (cost=75.90..130.38 rows=1 width=8)
Hash Cond: (csrr.id = "ANY_subquery".max)
-> Seq Scan on tbl_client_sales_rep_rels csrr (cost=0.00..54.46 rows=2 width=12)
Filter: (client_id = 149)
-> Hash (cost=73.40..73.40 rows=200 width=4)
-> HashAggregate (cost=71.40..73.40 rows=200 width=4)
Group Key: "ANY_subquery".max
-> Subquery Scan on "ANY_subquery" (cost=52.50..69.30 rows=840 width=4)
-> HashAggregate (cost=52.50..60.90 rows=840 width=8)
Group Key: csrrs.client_id
-> Seq Scan on tbl_client_sales_rep_rels csrrs (cost=0.00..47.57 rows=986 width=8)
Filter: (end_at IS NULL)
-> GroupAggregate (cost=4.63..102.31 rows=1 width=44)
Group Key: p.client_id
-> Bitmap Heap Scan on tbl_projects p (cost=4.63..102.29 rows=1 width=13)
Recheck Cond: (client_id = 149)
Filter: (project_status = 1)
-> Bitmap Index Scan on tbl_projects_client_id_idx (cost=0.00..4.62 rows=46 width=0)
Index Cond: (client_id = 149)
-> GroupAggregate (cost=4.63..102.31 rows=1 width=44)
Group Key: p_1.client_id
-> Bitmap Heap Scan on tbl_projects p_1 (cost=4.63..102.29 rows=1 width=13)
Recheck Cond: (client_id = 149)
Filter: (project_status = 2)
-> Bitmap Index Scan on tbl_projects_client_id_idx (cost=0.00..4.62 rows=46 width=0)
Index Cond: (client_id = 149)
-> GroupAggregate (cost=0.00..92.72 rows=17 width=28)
Group Key: ps.client_id
-> Seq Scan on tbl_pre_sales ps (cost=0.00..92.38 rows=17 width=24)
Filter: ((NOT is_draft) AND (client_id = 149))
-> Materialize (cost=4.63..103.48 rows=25 width=80)
-> Subquery Scan on tmp1 (cost=4.63..103.36 rows=25 width=80)
-> GroupAggregate (cost=4.63..103.11 rows=25 width=80)
Group Key: p_2.client_id
-> Bitmap Heap Scan on tbl_projects p_2 (cost=4.63..102.29 rows=25 width=22)
Recheck Cond: (client_id = 149)
Filter: (project_status = 3)
-> Bitmap Index Scan on tbl_projects_client_id_idx (cost=0.00..4.62 rows=46 width=0)
Index Cond: (client_id = 149)
-> Materialize (cost=0.00..365.30 rows=177 width=28)
-> Subquery Scan on tmp5 (cost=0.00..364.42 rows=177 width=28)
-> GroupAggregate (cost=0.00..362.65 rows=177 width=28)
Group Key: ir.client_id
-> Seq Scan on tbl_implement_records ir (cost=0.00..357.85 rows=303 width=24)
Filter: ((NOT is_draft) AND (client_id = 149))
-> Hash (cost=1.25..1.25 rows=25 width=150)
-> Seq Scan on tbl_client_industries ci (cost=0.00..1.25 rows=25 width=150)
-> Hash (cost=645.82..645.82 rows=2 width=28)
-> Subquery Scan on tmp7 (cost=6.80..645.82 rows=2 width=28)
-> GroupAggregate (cost=6.80..645.80 rows=2 width=28)
Group Key: wl.client_id
-> Bitmap Heap Scan on tbl_work_logs wl (cost=6.80..645.76 rows=2 width=24)
Recheck Cond: ((client_id IS NOT NULL) AND (client_id = 149))
Filter: ((NOT is_draft) AND (location_in_id IS NOT NULL) AND (location_out_id IS NOT NULL))
-> Bitmap Index Scan on tbl_work_logs_client_id_idx (cost=0.00..6.80 rows=251 width=0)
Index Cond: ((client_id IS NOT NULL) AND (client_id = 149))
-> Hash (cost=275.24..275.24 rows=155 width=36)
-> Subquery Scan on tmp8 (cost=0.00..275.24 rows=155 width=36)
-> GroupAggregate (cost=0.00..273.69 rows=155 width=36)
Group Key: r.client_id
-> Seq Scan on tbl_reimbursements r (cost=0.00..270.81 rows=190 width=9)
Filter: ((status = ANY ('{2,3}'::integer[])) AND (client_id = 149))
-> Hash (cost=504.41..504.41 rows=200 width=36)
-> Subquery Scan on tmp9 (cost=491.19..504.41 rows=200 width=36)
-> GroupAggregate (cost=491.19..502.41 rows=200 width=36)
Group Key: c_1.client_id
-> HashAggregate (cost=491.19..495.15 rows=317 width=40)
Group Key: c_1.id
-> Hash Right Join (cost=292.39..489.59 rows=319 width=16)
Hash Cond: (ca.case_id = c_1.id)
-> Seq Scan on tbl_case_assignments ca (cost=0.00..174.70 rows=8570 width=12)
-> Hash (cost=288.43..288.43 rows=317 width=8)
-> Seq Scan on tbl_cases c_1 (cost=0.00..288.43 rows=317 width=8)
Filter: (client_id = 149)