QUERY PLAN
Aggregate (cost=238.23..238.24 rows=1 width=32)
-> Nested Loop (cost=230.18..238.23 rows=1 width=6)
-> Group (cost=229.90..229.91 rows=1 width=4)
Group Key: c.id
-> Sort (cost=229.90..229.91 rows=1 width=4)
Sort Key: c.id
-> Nested Loop Left Join (cost=179.16..229.89 rows=1 width=4)
-> Hash Join (cost=179.02..229.03 rows=1 width=8)
Hash Cond: (c.client_id = client.id)
-> Hash Right Join (cost=68.68..118.60 rows=34 width=8)
Hash Cond: (sci2.contract_id = c.id)
-> Seq Scan on tbl_sales_contract_invoices sci2 (cost=0.00..44.52 rows=2052 width=4)
-> Hash (cost=68.32..68.32 rows=29 width=12)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..68.32 rows=29 width=12)
Filter: ((from_project IS NULL) AND build_by_project)
-> Hash (cost=109.58..109.58 rows=61 width=8)
-> Bitmap Heap Scan on tbl_clients client (cost=14.48..109.58 rows=61 width=8)
Recheck Cond: (sales_rep = 1001)
-> Bitmap Index Scan on tbl_clients_sales_rep_idx (cost=0.00..4.80 rows=70 width=0)
Index Cond: (sales_rep = 1001)
-> Index Only Scan using tbl_sales_group_relationships_pkey on tbl_sales_group_relationships sgr (cost=0.14..0.86 rows=1 width=4)
Index Cond: ((sales_id = client.sales_rep) AND (sales_id = 1001))
-> Index Scan using tbl_sales_contracts_pkey on tbl_sales_contracts (cost=0.28..8.29 rows=1 width=10)
Index Cond: (id = c.id)