QUERY PLAN
Aggregate (cost=121.22..121.23 rows=1 width=32)
-> Hash Join (cost=120.12..121.21 rows=2 width=5)
Hash Cond: (tbl_purchase_contracts.id = c.id)
-> Seq Scan on tbl_purchase_contracts (cost=0.00..1.06 rows=6 width=9)
Filter: including_tax
-> Hash (cost=120.10..120.10 rows=2 width=4)
-> HashAggregate (cost=120.06..120.08 rows=2 width=4)
Group Key: c.id
-> Hash Left Join (cost=78.18..120.02 rows=17 width=4)
Hash Cond: (c.id = cs.object_id)
-> Nested Loop (cost=44.95..86.71 rows=17 width=4)
-> Index Only Scan using tbl_sales_group_relationships_pkey on tbl_sales_group_relationships sgr (cost=0.15..8.17 rows=1 width=4)
Index Cond: ((group_id = 2) AND (sales_id = 5495))
-> Hash Join (cost=44.79..78.36 rows=17 width=8)
Hash Cond: (pcr.contract_id = c.id)
-> Hash Join (cost=43.69..77.13 rows=51 width=8)
Hash Cond: (pcr.client_id = client.id)
Join Filter: ((client.sales_rep = ANY ('{5495,5493}'::integer[])) OR (client.sales_rep IS NULL) OR (hashed SubPlan 1) OR (pcr.id IS NULL))
-> Seq Scan on tbl_purchase_client_rels pcr (cost=0.00..28.50 rows=1850 width=12)
-> Hash (cost=8.15..8.15 rows=1 width=8)
-> Index Scan using tbl_clients_sales_rep_idx on tbl_clients client (cost=0.14..8.15 rows=1 width=8)
Index Cond: (sales_rep = 5495)
SubPlan 1
-> Seq Scan on tbl_user_visit_clients (cost=0.00..35.50 rows=10 width=4)
Filter: (user_id = 5495)
-> Hash (cost=1.07..1.07 rows=2 width=8)
-> Seq Scan on tbl_purchase_contracts c (cost=0.00..1.07 rows=2 width=8)
Filter: ((NOT is_chargeback) AND (NOT is_draft) AND (NOT is_refuse) AND (cost_type = 1))
-> Hash (cost=33.12..33.12 rows=9 width=4)
-> Seq Scan on tbl_attachement_relationships cs (cost=0.00..33.12 rows=9 width=4)
Filter: (object_type = 108)