QUERY PLAN
Aggregate (cost=638.67..638.68 rows=1 width=32)
-> HashAggregate (cost=620.05..632.02 rows=532 width=36)
Group Key: sc.id
-> Hash Right Join (cost=564.21..614.73 rows=532 width=17)
Hash Cond: (sci.contract_id = sc.id)
-> Seq Scan on tbl_sales_contract_invoices sci (cost=0.00..38.34 rows=1834 width=10)
-> Hash (cost=558.46..558.46 rows=460 width=11)
-> Hash Join (cost=327.46..558.46 rows=460 width=11)
Hash Cond: (sc.project_id = p.id)
-> Seq Scan on tbl_sales_contracts sc (cost=0.00..226.84 rows=1583 width=15)
Filter: including_tax
-> Hash (cost=316.85..316.85 rows=849 width=4)
-> Seq Scan on tbl_projects p (cost=0.00..316.85 rows=849 width=4)
Filter: (created_by = ANY ('{1004,1005,1013,5087}'::integer[]))