QUERY PLAN
Aggregate (cost=269.44..269.45 rows=1 width=32)
-> HashAggregate (cost=266.12..268.25 rows=95 width=36)
Group Key: sc.id
-> Nested Loop Left Join (cost=161.67..265.17 rows=95 width=17)
-> Hash Join (cost=161.39..234.27 rows=81 width=11)
Hash Cond: (sc.project_id = p.id)
-> Seq Scan on tbl_sales_contracts sc (cost=0.00..68.32 rows=1731 width=15)
Filter: including_tax
-> Hash (cost=159.54..159.54 rows=148 width=4)
-> Bitmap Heap Scan on tbl_projects p (cost=5.43..159.54 rows=148 width=4)
Recheck Cond: (created_by = 1001)
-> Bitmap Index Scan on tbl_projects_created_by_idx (cost=0.00..5.39 rows=148 width=0)
Index Cond: (created_by = 1001)
-> Index Scan using tbl_sales_contract_invoices_contract_id_idx on tbl_sales_contract_invoices sci (cost=0.28..0.37 rows=1 width=10)
Index Cond: (sc.id = contract_id)