QUERY PLAN
Aggregate (cost=18343.82..18343.83 rows=1 width=32)
-> Nested Loop Semi Join (cost=18240.89..18343.73 rows=35 width=33)
-> Seq Scan on tbl_sales_contracts (cost=0.00..10.70 rows=35 width=37)
Filter: including_tax
-> Hash Join (cost=18240.89..18243.51 rows=1 width=4)
Hash Cond: (p.id = tbl_sales_contracts_1.from_project)
-> HashAggregate (cost=18239.34..18240.44 rows=110 width=4)
Group Key: p.id
-> Hash Right Join (cost=1068.22..13642.61 rows=1838693 width=4)
Hash Cond: (pa.project_id = p.id)
-> Merge Left Join (cost=204.38..343.42 rows=8976 width=4)
Merge Cond: (pa.engineer_id = egr.engineer_id)
-> Sort (cost=61.84..64.04 rows=880 width=8)
Sort Key: pa.engineer_id
-> Seq Scan on tbl_project_architects pa (cost=0.00..18.80 rows=880 width=8)
-> Sort (cost=142.54..147.64 rows=2040 width=4)
Sort Key: egr.engineer_id
-> Seq Scan on tbl_engineer_group_relationships egr (cost=0.00..30.40 rows=2040 width=4)
-> Hash (cost=582.18..582.18 rows=22533 width=4)
-> Hash Left Join (cost=326.62..582.18 rows=22533 width=4)
Hash Cond: (p.id = ttr2.object_id)
-> Hash Right Join (cost=309.96..477.64 rows=22533 width=4)
Hash Cond: (sl.project_id = p.id)
-> Seq Scan on tbl_work_logs sl (cost=0.00..14.50 rows=450 width=4)
-> Hash (cost=241.11..241.11 rows=5508 width=4)
-> Hash Join (cost=166.25..241.11 rows=5508 width=4)
Hash Cond: (c.id = p.client_id)
Join Filter: ((c.sales_rep IS NULL) OR (c.sales_rep = 5493) OR (prr.user_id = 5495) OR (hashed SubPlan 1))
-> Hash Right Join (cost=10.32..49.39 rows=102 width=8)
Hash Cond: (sgr.sales_id = c.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=10 width=8)
-> Seq Scan on tbl_clients c (cost=0.00..10.20 rows=10 width=8)
Filter: ((NOT deleted) AND (id IS NOT NULL))
-> Hash (cost=94.90..94.90 rows=2040 width=12)
-> Hash Right Join (cost=45.63..94.90 rows=2040 width=12)
Hash Cond: (prr.project_id = p.id)
-> Seq Scan on tbl_project_remind_receivers prr (cost=0.00..30.40 rows=2040 width=8)
-> Hash (cost=44.26..44.26 rows=110 width=8)
-> Hash Left Join (cost=32.30..44.26 rows=110 width=8)
Hash Cond: (p.id = ttr.object_id)
-> Hash Left Join (cost=15.64..27.16 rows=110 width=8)
Hash Cond: (p.id = arrive.project_id)
-> Seq Scan on tbl_projects p (cost=0.00..11.10 rows=110 width=12)
-> Hash (cost=15.62..15.62 rows=1 width=4)
-> Seq Scan on tbl_work_logs arrive (cost=0.00..15.62 rows=1 width=4)
Filter: ((NOT is_draft) AND (location_in_id IS NOT NULL) AND (location_out_id IS NOT NULL) AND (client_id IS NOT NULL) AND (scenario_id = 1))
-> Hash (cost=16.62..16.62 rows=3 width=4)
-> Seq Scan on tbl_term_taxonomy_relationships ttr (cost=0.00..16.62 rows=3 width=4)
Filter: (term_id = 10)
SubPlan 1
-> Seq Scan on tbl_user_visit_clients (cost=0.00..35.50 rows=10 width=4)
Filter: (user_id = 5495)
-> Hash (cost=16.62..16.62 rows=3 width=4)
-> Seq Scan on tbl_term_taxonomy_relationships ttr2 (cost=0.00..16.62 rows=3 width=4)
Filter: (term_id = 13)
-> Hash (cost=1.53..1.53 rows=1 width=8)
-> Index Scan using tbl_sales_contracts_pkey on tbl_sales_contracts tbl_sales_contracts_1 (cost=0.14..1.53 rows=1 width=8)
Index Cond: (id = tbl_sales_contracts.id)