QUERY PLAN
Aggregate (cost=139.56..139.57 rows=1 width=32)
-> Hash Join (cost=128.49..139.38 rows=70 width=33)
Hash Cond: (tbl_sales_contracts.id = c.id)
-> Seq Scan on tbl_sales_contracts (cost=0.00..10.70 rows=70 width=37)
-> Hash (cost=127.61..127.61 rows=70 width=4)
-> HashAggregate (cost=126.21..126.91 rows=70 width=4)
Group Key: c.id
-> Hash Right Join (cost=72.84..123.38 rows=1132 width=4)
Hash Cond: (client.id = c.client_id)
Filter: ((client.sales_rep = 5493) OR (client.sales_rep IS NULL) OR (hashed SubPlan 1))
-> Hash Right Join (cost=10.45..50.54 rows=204 width=8)
Hash Cond: (sgr.sales_id = client.sales_rep)
-> Seq Scan on tbl_sales_group_relationships sgr (cost=0.00..30.40 rows=2040 width=4)
-> Hash (cost=10.20..10.20 rows=20 width=8)
-> Seq Scan on tbl_clients client (cost=0.00..10.20 rows=20 width=8)
-> Hash (cost=24.24..24.24 rows=210 width=8)
-> Hash Right Join (cost=11.57..24.24 rows=210 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=10.70..10.70 rows=70 width=12)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..10.70 rows=70 width=12)
Filter: (from_project IS NOT NULL)
SubPlan 1
-> Seq Scan on tbl_user_visit_clients (cost=0.00..35.50 rows=10 width=4)
Filter: (user_id = 5495)