QUERY PLAN
Aggregate (cost=118.83..118.84 rows=1 width=32)
-> Hash Join (cost=105.98..118.64 rows=74 width=32)
Hash Cond: (tbl_sales_contract_invoices.contract_id = c.id)
-> Seq Scan on tbl_sales_contract_invoices (cost=0.00..12.10 rows=210 width=36)
-> Hash (cost=105.11..105.11 rows=70 width=4)
-> HashAggregate (cost=103.71..104.41 rows=70 width=4)
Group Key: c.id
-> Nested Loop Left Join (cost=78.10..103.41 rows=120 width=4)
Join Filter: (sgr.sales_id = client.sales_rep)
-> Hash Right Join (cost=54.64..67.57 rows=12 width=8)
Hash Cond: (sci2.contract_id = c.id)
-> Seq Scan on tbl_sales_contract_invoices sci2 (cost=0.00..12.10 rows=210 width=4)
-> Hash (cost=54.59..54.59 rows=4 width=8)
-> Hash Join (cost=43.70..54.59 rows=4 width=8)
Hash Cond: (c.client_id = client.id)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..10.70 rows=70 width=12)
Filter: (from_project IS NOT NULL)
-> Hash (cost=43.69..43.69 rows=1 width=8)
-> Index Scan using tbl_clients_sales_rep_idx on tbl_clients client (cost=35.66..43.69 rows=1 width=8)
Index Cond: (sales_rep = 5493)
-> Materialize (cost=23.45..34.06 rows=10 width=4)
-> Bitmap Heap Scan on tbl_sales_group_relationships sgr (cost=23.45..34.01 rows=10 width=4)
Recheck Cond: (sales_id = 5493)
-> Bitmap Index Scan on tbl_sales_group_relationships_pkey (cost=0.00..23.45 rows=10 width=0)
Index Cond: (sales_id = 5493)