QUERY PLAN
Sort (cost=7181.72..7182.00 rows=112 width=477)
Sort Key: p.created_at DESC
-> HashAggregate (cost=2284.34..7177.90 rows=112 width=477)
Group Key: p.id
-> Merge Right Join (cost=1231.17..2268.42 rows=1274 width=365)
Merge Cond: (sl.project_id = p.id)
-> Index Scan using tbl_work_logs_project_id_idx on tbl_work_logs sl (cost=0.29..6291.82 rows=35731 width=12)
-> Sort (cost=1230.88..1231.16 rows=112 width=357)
Sort Key: p.id
-> Merge Right Join (cost=188.38..1227.07 rows=112 width=357)
Merge Cond: (arrive.project_id = p.id)
-> Index Scan using tbl_work_logs_project_id_idx on tbl_work_logs arrive (cost=0.29..6381.15 rows=209 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))
-> Sort (cost=188.09..188.37 rows=112 width=349)
Sort Key: p.id
-> Seq Scan on tbl_projects p (cost=0.00..184.28 rows=112 width=349)
Filter: (creator = 1001)
SubPlan 1
-> Aggregate (cost=43.63..43.64 rows=1 width=32)
-> Seq Scan on tbl_invoices i (cost=0.00..43.62 rows=1 width=6)
Filter: (project_id = p.id)