QUERY PLAN
Aggregate (cost=2291.43..2291.44 rows=1 width=32)
-> Hash Semi Join (cost=2277.35..2291.17 rows=105 width=32)
Hash Cond: (tbl_sales_contract_invoices.contract_id = tbl_sales_contracts.id)
-> Seq Scan on tbl_sales_contract_invoices (cost=0.00..12.10 rows=210 width=36)
-> Hash (cost=2276.91..2276.91 rows=35 width=8)
-> Merge Semi Join (cost=2276.03..2276.91 rows=35 width=8)
Merge Cond: (tbl_sales_contracts.id = tbl_sales_contracts_1.id)
-> Sort (cost=11.60..11.69 rows=35 width=4)
Sort Key: tbl_sales_contracts.id
-> Seq Scan on tbl_sales_contracts (cost=0.00..10.70 rows=35 width=4)
Filter: including_tax
-> Sort (cost=2264.44..2264.61 rows=70 width=4)
Sort Key: tbl_sales_contracts_1.id
-> Hash Join (cost=2251.40..2262.29 rows=70 width=4)
Hash Cond: (tbl_sales_contracts_1.from_project = p.id)
-> Seq Scan on tbl_sales_contracts tbl_sales_contracts_1 (cost=0.00..10.70 rows=70 width=8)
-> Hash (cost=2250.02..2250.02 rows=110 width=4)
-> HashAggregate (cost=2247.82..2248.92 rows=110 width=4)
Group Key: p.id
-> Hash Right Join (cost=419.91..1797.19 rows=180254 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=187.91..187.91 rows=2209 width=4)
-> Hash Left Join (cost=113.86..187.91 rows=2209 width=4)
Hash Cond: (p.id = ttr2.object_id)
-> Hash Left Join (cost=97.20..162.64 rows=2209 width=4)
Hash Cond: (c.sales_rep = sgr.sales_id)
-> Hash Right Join (cost=63.06..105.57 rows=221 width=8)
Hash Cond: (prr.project_id = p.id)
Filter: ((c.sales_rep IS NULL) OR (c.sales_rep = 5493) OR (prr.user_id = 5493) OR (hashed SubPlan 1))
-> Seq Scan on tbl_project_remind_receivers prr (cost=0.00..30.40 rows=2040 width=8)
-> Hash (cost=27.22..27.22 rows=25 width=12)
-> Nested Loop Left Join (cost=0.72..27.22 rows=25 width=12)
-> Nested Loop Left Join (cost=0.58..23.61 rows=6 width=12)
-> Nested Loop Left Join (cost=0.43..19.91 rows=6 width=12)
-> Nested Loop (cost=0.28..16.33 rows=6 width=12)
-> Index Scan using tbl_clients_sales_rep_idx on tbl_clients c (cost=0.14..8.15 rows=1 width=8)
Index Cond: (sales_rep = 5493)
Filter: ((NOT deleted) AND (id IS NOT NULL))
-> Index Scan using tbl_projects_client_id_idx on tbl_projects p (cost=0.14..8.16 rows=1 width=12)
Index Cond: (client_id = c.id)
-> Index Scan using tbl_work_logs_project_id_idx on tbl_work_logs arrive (cost=0.15..0.59 rows=1 width=4)
Index Cond: (project_id = p.id)
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))
-> Index Only Scan using tbl_term_taxonomy_relationships_object_id_term_id_idx on tbl_term_taxonomy_relationships ttr (cost=0.15..0.61 rows=1 width=4)
Index Cond: ((object_id = p.id) AND (term_id = 10))
-> Index Only Scan using tbl_work_logs_project_id_idx on tbl_work_logs sl (cost=0.15..0.58 rows=2 width=4)
Index Cond: (project_id = p.id)
SubPlan 1
-> Seq Scan on tbl_user_visit_clients (cost=0.00..35.50 rows=10 width=4)
Filter: (user_id = 5493)
-> Hash (cost=34.01..34.01 rows=10 width=4)
-> Bitmap Heap Scan on tbl_sales_group_relationships sgr (cost=23.45..34.01 rows=10 width=4)
Recheck Cond: (sales_id = 5493)
-> Bitmap Index Scan on tbl_sales_group_relationships_pkey (cost=0.00..23.45 rows=10 width=0)
Index Cond: (sales_id = 5493)
-> 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)