QUERY PLAN
Aggregate (cost=1228.73..1228.74 rows=1 width=8)
-> HashAggregate (cost=1228.69..1228.71 rows=2 width=826)
Group Key: p.id
-> Merge Right Join (cost=623.01..1143.62 rows=34027 width=4)
Merge Cond: (egr.engineer_id = pa.engineer_id)
-> 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)
-> Sort (cost=480.47..488.81 rows=3336 width=8)
Sort Key: pa.engineer_id
-> Hash Left Join (cost=160.04..285.25 rows=3336 width=8)
Hash Cond: (p.id = pa.project_id)
-> Hash Left Join (cost=130.24..190.19 rows=417 width=4)
Hash Cond: (p.id = ttr2.object_id)
-> Hash Left Join (cost=113.57..171.90 rows=417 width=4)
Hash Cond: (p.id = sl.project_id)
-> Hash Right Join (cost=93.45..143.48 rows=102 width=4)
Hash Cond: (prr.project_id = p.id)
Filter: ((c.sales_rep IS NULL) OR (c.sales_rep = 5493) OR (prr.user_id = 5495) OR (hashed SubPlan 1))
-> Seq Scan on tbl_project_remind_receivers prr (cost=0.00..30.40 rows=2040 width=8)
-> Hash (cost=57.80..57.80 rows=10 width=12)
-> Nested Loop Left Join (cost=13.87..57.80 rows=10 width=12)
-> Nested Loop Left Join (cost=13.71..37.35 rows=1 width=12)
-> Nested Loop Left Join (cost=13.56..29.17 rows=1 width=12)
-> Hash Join (cost=11.40..21.65 rows=1 width=12)
Hash Cond: (c.id = p.client_id)
-> 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=11.38..11.38 rows=2 width=12)
-> Seq Scan on tbl_projects p (cost=0.00..11.38 rows=2 width=12)
Filter: (project_status = ANY ('{1,2}'::integer[]))
-> Bitmap Heap Scan on tbl_work_logs arrive (cost=2.16..7.51 rows=1 width=4)
Recheck 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))
-> Bitmap Index Scan on tbl_work_logs_project_id_idx (cost=0.00..2.16 rows=2 width=0)
Index Cond: (project_id = p.id)
-> Index Only Scan using tbl_term_taxonomy_relationships_object_id_term_id_idx on tbl_term_taxonomy_relationships ttr (cost=0.15..8.17 rows=1 width=4)
Index Cond: ((object_id = p.id) AND (term_id = 10))
-> Index Only Scan using tbl_sales_group_relationships_pkey on tbl_sales_group_relationships sgr (cost=0.15..20.35 rows=10 width=4)
Index Cond: (sales_id = c.sales_rep)
SubPlan 1
-> Seq Scan on tbl_user_visit_clients (cost=0.00..35.50 rows=10 width=4)
Filter: (user_id = 5495)
-> Hash (cost=14.50..14.50 rows=450 width=4)
-> Seq Scan on tbl_work_logs sl (cost=0.00..14.50 rows=450 width=4)
-> 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=18.80..18.80 rows=880 width=8)
-> Seq Scan on tbl_project_architects pa (cost=0.00..18.80 rows=880 width=8)