QUERY PLAN
Hash Left Join (cost=1017.39..68093.17 rows=2609568 width=394)
Hash Cond: (c.id = tmp9.client_id)
-> Hash Left Join (cost=526.62..1488.04 rows=63648 width=329)
Hash Cond: (c.id = tmp8.client_id)
-> Nested Loop Left Join (cost=96.17..1023.93 rows=2448 width=297)
Join Filter: (tmp7.client_id = c.id)
-> Hash Left Join (cost=91.18..764.23 rows=1224 width=273)
Hash Cond: (c.client_industry = ci.id)
-> Nested Loop Left Join (cost=89.62..758.93 rows=1224 width=265)
Join Filter: (tmp4.client_id = c.id)
-> Nested Loop Left Join (cost=89.62..663.84 rows=72 width=241)
Join Filter: (tmp1.client_id = c.id)
-> Nested Loop Left Join (cost=85.21..607.88 rows=8 width=165)
Join Filter: (ir.client_id = c.id)
-> Nested Loop Left Join (cost=85.21..249.75 rows=1 width=141)
Join Filter: (p_1.client_id = c.id)
-> Nested Loop Left Join (cost=80.80..194.39 rows=1 width=101)
Join Filter: (p.client_id = c.id)
-> Nested Loop Left Join (cost=76.39..139.03 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 = 2128)
-> Hash Join (cost=76.11..130.72 rows=1 width=8)
Hash Cond: (csrr.id = "ANY_subquery".max)
-> Seq Scan on tbl_client_sales_rep_rels csrr (cost=0.00..54.59 rows=2 width=12)
Filter: (client_id = 2128)
-> Hash (cost=73.61..73.61 rows=200 width=4)
-> HashAggregate (cost=71.61..73.61 rows=200 width=4)
Group Key: "ANY_subquery".max
-> Subquery Scan on "ANY_subquery" (cost=52.62..69.50 rows=844 width=4)
-> HashAggregate (cost=52.62..61.06 rows=844 width=8)
Group Key: csrrs.client_id
-> Seq Scan on tbl_client_sales_rep_rels csrrs (cost=0.00..47.67 rows=991 width=8)
Filter: (end_at IS NULL)
-> GroupAggregate (cost=4.41..55.34 rows=1 width=44)
Group Key: p.client_id
-> Bitmap Heap Scan on tbl_projects p (cost=4.41..55.32 rows=1 width=13)
Recheck Cond: (client_id = 2128)
Filter: (project_status = 1)
-> Bitmap Index Scan on tbl_projects_client_id_idx (cost=0.00..4.41 rows=17 width=0)
Index Cond: (client_id = 2128)
-> GroupAggregate (cost=4.41..55.34 rows=1 width=44)
Group Key: p_1.client_id
-> Bitmap Heap Scan on tbl_projects p_1 (cost=4.41..55.32 rows=1 width=13)
Recheck Cond: (client_id = 2128)
Filter: (project_status = 2)
-> Bitmap Index Scan on tbl_projects_client_id_idx (cost=0.00..4.41 rows=17 width=0)
Index Cond: (client_id = 2128)
-> GroupAggregate (cost=0.00..358.02 rows=8 width=28)
Group Key: ir.client_id
-> Seq Scan on tbl_implement_records ir (cost=0.00..357.86 rows=8 width=24)
Filter: ((NOT is_draft) AND (client_id = 2128))
-> Materialize (cost=4.41..55.75 rows=9 width=80)
-> Subquery Scan on tmp1 (cost=4.41..55.70 rows=9 width=80)
-> GroupAggregate (cost=4.41..55.61 rows=9 width=80)
Group Key: p_2.client_id
-> Bitmap Heap Scan on tbl_projects p_2 (cost=4.41..55.32 rows=9 width=22)
Recheck Cond: (client_id = 2128)
Filter: (project_status = 3)
-> Bitmap Index Scan on tbl_projects_client_id_idx (cost=0.00..4.41 rows=17 width=0)
Index Cond: (client_id = 2128)
-> Materialize (cost=0.00..93.06 rows=17 width=28)
-> Subquery Scan on tmp4 (cost=0.00..92.97 rows=17 width=28)
-> GroupAggregate (cost=0.00..92.80 rows=17 width=28)
Group Key: ps.client_id
-> Seq Scan on tbl_pre_sales ps (cost=0.00..92.46 rows=17 width=24)
Filter: ((NOT is_draft) AND (client_id = 2128))
-> Hash (cost=1.25..1.25 rows=25 width=12)
-> Seq Scan on tbl_client_industries ci (cost=0.00..1.25 rows=25 width=12)
-> Materialize (cost=4.99..235.22 rows=2 width=28)
-> Subquery Scan on tmp7 (cost=4.99..235.21 rows=2 width=28)
-> GroupAggregate (cost=4.99..235.19 rows=2 width=28)
Group Key: wl.client_id
-> Bitmap Heap Scan on tbl_work_logs wl (cost=4.99..235.15 rows=2 width=24)
Recheck Cond: ((client_id IS NOT NULL) AND (client_id = 2128))
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..4.99 rows=70 width=0)
Index Cond: ((client_id IS NOT NULL) AND (client_id = 2128))
-> Hash (cost=430.12..430.12 rows=26 width=36)
-> Subquery Scan on tmp8 (cost=0.00..430.12 rows=26 width=36)
-> GroupAggregate (cost=0.00..429.86 rows=26 width=36)
Group Key: r.client_id
-> Seq Scan on tbl_reimbursements r (cost=0.00..429.40 rows=27 width=9)
Filter: ((status = ANY ('{2,3}'::integer[])) AND (client_id = 2128))
-> Hash (cost=490.25..490.25 rows=41 width=36)
-> Subquery Scan on tmp9 (cost=487.90..490.25 rows=41 width=36)
-> GroupAggregate (cost=487.90..489.84 rows=41 width=36)
Group Key: c_1.client_id
-> GroupAggregate (cost=487.90..488.72 rows=41 width=40)
Group Key: c_1.id
-> Sort (cost=487.90..488.00 rows=41 width=16)
Sort Key: c_1.id
-> Hash Right Join (cost=289.27..486.80 rows=41 width=16)
Hash Cond: (ca.case_id = c_1.id)
-> Seq Scan on tbl_case_assignments ca (cost=0.00..174.95 rows=8595 width=12)
-> Hash (cost=288.76..288.76 rows=41 width=8)
-> Seq Scan on tbl_cases c_1 (cost=0.00..288.76 rows=41 width=8)
Filter: (client_id = 2128)