QUERY PLAN
Sort (cost=6378.93..6379.19 rows=105 width=484)
Sort Key: p.created_at DESC
-> HashAggregate (cost=2253.63..6375.40 rows=105 width=484)
Group Key: p.id
-> Merge Right Join (cost=1211.18..2238.18 rows=1236 width=372)
Merge Cond: (sl.project_id = p.id)
-> Index Scan using tbl_work_logs_project_id_idx on tbl_work_logs sl (cost=0.29..6089.03 rows=34465 width=12)
-> Sort (cost=1210.89..1211.15 rows=105 width=364)
Sort Key: p.id
-> Merge Right Join (cost=177.40..1207.36 rows=105 width=364)
Merge Cond: (arrive.project_id = p.id)
-> Index Scan using tbl_work_logs_project_id_idx on tbl_work_logs arrive (cost=0.29..6175.19 rows=594 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=177.11..177.37 rows=105 width=356)
Sort Key: p.id
-> Seq Scan on tbl_projects p (cost=0.00..173.59 rows=105 width=356)
Filter: (creator = 1001)
SubPlan 1
-> Aggregate (cost=39.19..39.20 rows=1 width=32)
-> Seq Scan on tbl_invoices i (cost=0.00..39.19 rows=1 width=6)
Filter: (project_id = p.id)