QUERY PLAN
Sort (cost=6459.99..6460.26 rows=106 width=483)
Sort Key: p.created_at DESC
-> HashAggregate (cost=2267.57..6456.43 rows=106 width=483)
Group Key: p.id
-> Merge Right Join (cost=1218.10..2252.11 rows=1237 width=371)
Merge Cond: (sl.project_id = p.id)
-> Index Scan using tbl_work_logs_project_id_idx on tbl_work_logs sl (cost=0.29..6120.49 rows=34624 width=12)
-> Sort (cost=1217.81..1218.07 rows=106 width=363)
Sort Key: p.id
-> Merge Right Join (cost=178.96..1214.24 rows=106 width=363)
Merge Cond: (arrive.project_id = p.id)
-> Index Scan using tbl_work_logs_project_id_idx on tbl_work_logs arrive (cost=0.29..6207.05 rows=618 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=178.67..178.93 rows=106 width=355)
Sort Key: p.id
-> Seq Scan on tbl_projects p (cost=0.00..175.10 rows=106 width=355)
Filter: (creator = 1001)
SubPlan 1
-> Aggregate (cost=39.45..39.46 rows=1 width=32)
-> Seq Scan on tbl_invoices i (cost=0.00..39.45 rows=1 width=6)
Filter: (project_id = p.id)