QUERY PLAN
Aggregate (cost=372.25..372.26 rows=1 width=8)
-> Sort (cost=372.24..372.24 rows=1 width=826)
Sort Key: p.bargain_date DESC, p.created_at DESC
-> HashAggregate (cost=372.22..372.23 rows=1 width=826)
Group Key: p.id
-> Hash Right Join (cost=210.74..363.85 rows=3346 width=16)
Hash Cond: (egr.engineer_id = pa.engineer_id)
-> Seq Scan on tbl_engineer_group_relationships egr (cost=0.00..30.40 rows=2040 width=4)
-> Hash (cost=206.64..206.64 rows=328 width=20)
-> Hash Left Join (cost=113.60..206.64 rows=328 width=20)
Hash Cond: (p.id = pa.project_id)
-> Nested Loop Left Join (cost=83.80..170.43 rows=41 width=16)
Join Filter: (ttr2.object_id = p.id)
-> Nested Loop Left Join (cost=83.80..151.95 rows=41 width=16)
Join Filter: (sgr.sales_id = c.sales_rep)
-> Nested Loop Left Join (cost=60.34..117.32 rows=4 width=20)
-> Nested Loop Left Join (cost=56.18..107.79 rows=1 width=20)
-> Nested Loop Left Join (cost=56.03..99.61 rows=1 width=20)
-> Hash Right Join (cost=51.87..90.09 rows=1 width=20)
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=16.33..16.33 rows=1 width=24)
-> Nested Loop (cost=0.28..16.33 rows=1 width=24)
-> 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.17 rows=1 width=24)
Index Cond: (client_id = c.id)
Filter: ((budget > collected) AND (project_status = 3))
SubPlan 1
-> Seq Scan on tbl_user_visit_clients (cost=0.00..35.50 rows=10 width=4)
Filter: (user_id = 5493)
-> Bitmap Heap Scan on tbl_work_logs arrive (cost=4.16..9.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..4.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))
-> Bitmap Heap Scan on tbl_work_logs sl (cost=4.16..9.50 rows=2 width=4)
Recheck Cond: (project_id = p.id)
-> Bitmap Index Scan on tbl_work_logs_project_id_idx (cost=0.00..4.16 rows=2 width=0)
Index Cond: (project_id = p.id)
-> Materialize (cost=23.45..34.06 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)
-> Materialize (cost=0.00..16.64 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)