QUERY PLAN
Limit (cost=839.77..1261.42 rows=20 width=826)
-> Result (cost=839.77..3158.85 rows=110 width=826)
-> Sort (cost=839.77..840.05 rows=110 width=794)
Sort Key: p.bargain_date DESC NULLS LAST, p.created_at DESC
-> HashAggregate (cost=830.52..836.85 rows=110 width=794)
Group Key: p.id
-> Hash Left Join (cost=383.30..728.15 rows=8190 width=682)
Hash Cond: (pa.engineer_id = egr.engineer_id)
-> Hash Left Join (cost=347.67..607.55 rows=819 width=686)
Hash Cond: (p.id = ttr2.object_id)
-> Hash Join (cost=331.01..587.70 rows=819 width=686)
Hash Cond: (p.id = pa.project_id)
-> Hash Right Join (cost=309.96..477.64 rows=22533 width=682)
Hash Cond: (sl.project_id = p.id)
-> Seq Scan on tbl_work_logs sl (cost=0.00..14.50 rows=450 width=12)
-> Hash (cost=241.11..241.11 rows=5508 width=674)
-> Hash Join (cost=166.25..241.11 rows=5508 width=674)
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 2))
-> 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=678)
-> Hash Right Join (cost=45.63..94.90 rows=2040 width=678)
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=674)
-> Hash Left Join (cost=32.30..44.26 rows=110 width=674)
Hash Cond: (p.id = ttr.object_id)
-> Hash Left Join (cost=15.64..27.16 rows=110 width=674)
Hash Cond: (p.id = arrive.project_id)
-> Seq Scan on tbl_projects p (cost=0.00..11.10 rows=110 width=666)
-> Hash (cost=15.62..15.62 rows=1 width=12)
-> Seq Scan on tbl_work_logs arrive (cost=0.00..15.62 rows=1 width=12)
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 2
-> Seq Scan on tbl_user_visit_clients (cost=0.00..35.50 rows=10 width=4)
Filter: (user_id = 5495)
-> Hash (cost=21.00..21.00 rows=4 width=8)
-> Seq Scan on tbl_project_architects pa (cost=0.00..21.00 rows=4 width=8)
Filter: (engineer_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=35.50..35.50 rows=10 width=4)
-> Seq Scan on tbl_engineer_group_relationships egr (cost=0.00..35.50 rows=10 width=4)
Filter: (engineer_id = 5495)
SubPlan 1
-> Aggregate (cost=21.01..21.02 rows=1 width=32)
-> Seq Scan on tbl_invoices i (cost=0.00..21.00 rows=4 width=32)
Filter: (project_id = p.id)