QUERY PLAN
Nested Loop Left Join (cost=65.98..182.32 rows=1 width=1007)
-> Nested Loop Left Join (cost=65.84..174.09 rows=1 width=828)
Join Filter: (c_1.client_id = c.id)
-> Nested Loop Left Join (cost=29.61..137.77 rows=1 width=796)
Join Filter: (r.client_id = c.id)
-> Nested Loop Left Join (cost=29.61..121.58 rows=1 width=764)
Join Filter: (wl.client_id = c.id)
-> Nested Loop Left Join (cost=25.44..112.03 rows=1 width=740)
Join Filter: (ir.client_id = c.id)
-> Nested Loop Left Join (cost=25.44..98.86 rows=1 width=716)
Join Filter: (ps.client_id = c.id)
-> Nested Loop Left Join (cost=25.44..85.82 rows=1 width=692)
Join Filter: (p_2.client_id = c.id)
-> Nested Loop Left Join (cost=25.30..77.61 rows=1 width=652)
Join Filter: (p_1.client_id = c.id)
-> Nested Loop Left Join (cost=25.16..69.41 rows=1 width=612)
Join Filter: (p.client_id = c.id)
-> Nested Loop Left Join (cost=25.02..61.19 rows=1 width=536)
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.14..8.15 rows=1 width=540)
Index Cond: (id = 1)
-> Hash Semi Join (cost=24.88..53.02 rows=1 width=8)
Hash Cond: (csrr.id = "ANY_subquery".max)
-> Seq Scan on tbl_client_sales_rep_rels csrr (cost=0.00..28.12 rows=7 width=12)
Filter: (client_id = 1)
-> Hash (cost=24.79..24.79 rows=7 width=4)
-> Subquery Scan on "ANY_subquery" (cost=24.60..24.79 rows=7 width=4)
-> GroupAggregate (cost=24.60..24.72 rows=7 width=8)
Group Key: csrrs.client_id
-> Sort (cost=24.60..24.62 rows=7 width=8)
Sort Key: csrrs.client_id
-> Seq Scan on tbl_client_sales_rep_rels csrrs (cost=0.00..24.50 rows=7 width=8)
Filter: (end_at IS NULL)
-> GroupAggregate (cost=0.14..8.20 rows=1 width=80)
Group Key: p.client_id
-> Index Scan using tbl_projects_client_id_idx on tbl_projects p (cost=0.14..8.16 rows=1 width=76)
Index Cond: (client_id = 1)
Filter: (project_status = 3)
-> GroupAggregate (cost=0.14..8.18 rows=1 width=44)
Group Key: p_1.client_id
-> Index Scan using tbl_projects_client_id_idx on tbl_projects p_1 (cost=0.14..8.16 rows=1 width=40)
Index Cond: (client_id = 1)
Filter: (project_status = 1)
-> GroupAggregate (cost=0.14..8.18 rows=1 width=44)
Group Key: p_2.client_id
-> Index Scan using tbl_projects_client_id_idx on tbl_projects p_2 (cost=0.14..8.16 rows=1 width=40)
Index Cond: (client_id = 1)
Filter: (project_status = 2)
-> GroupAggregate (cost=0.00..13.02 rows=1 width=28)
Group Key: ps.client_id
-> Seq Scan on tbl_pre_sales ps (cost=0.00..13.00 rows=1 width=24)
Filter: ((NOT is_draft) AND (client_id = 1))
-> GroupAggregate (cost=0.00..13.14 rows=1 width=28)
Group Key: ir.client_id
-> Seq Scan on tbl_implement_records ir (cost=0.00..13.12 rows=1 width=24)
Filter: ((NOT is_draft) AND (client_id = 1))
-> GroupAggregate (cost=4.17..9.53 rows=1 width=28)
Group Key: wl.client_id
-> Bitmap Heap Scan on tbl_work_logs wl (cost=4.17..9.51 rows=1 width=24)
Recheck Cond: ((client_id IS NOT NULL) AND (client_id = 1))
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.17 rows=2 width=0)
Index Cond: ((client_id IS NOT NULL) AND (client_id = 1))
-> GroupAggregate (cost=0.00..16.17 rows=1 width=36)
Group Key: r.client_id
-> Seq Scan on tbl_reimbursements r (cost=0.00..16.15 rows=1 width=36)
Filter: ((status = ANY ('{2,3}'::integer[])) AND (client_id = 1))
-> GroupAggregate (cost=36.22..36.29 rows=1 width=36)
Group Key: c_1.client_id
-> GroupAggregate (cost=36.22..36.27 rows=1 width=40)
Group Key: c_1.id
-> Sort (cost=36.22..36.23 rows=4 width=16)
Sort Key: c_1.id
-> Hash Right Join (cost=13.26..36.18 rows=4 width=16)
Hash Cond: (ca.case_id = c_1.id)
-> Seq Scan on tbl_case_assignments ca (cost=0.00..20.20 rows=1020 width=12)
-> Hash (cost=13.25..13.25 rows=1 width=8)
-> Seq Scan on tbl_cases c_1 (cost=0.00..13.25 rows=1 width=8)
Filter: (client_id = 1)
-> Index Scan using tbl_client_industries_pkey on tbl_client_industries ci (cost=0.15..8.17 rows=1 width=150)
Index Cond: (id = c.client_industry)