QUERY PLAN
Sort (cost=6504.86..6505.12 rows=105 width=484)
Sort Key: p.created_at DESC
-> HashAggregate (cost=2394.00..6501.33 rows=105 width=484)
Group Key: p.id
-> Merge Right Join (cost=1346.68..2378.53 rows=1237 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..6086.40 rows=34438 width=12)
-> Sort (cost=1346.39..1346.66 rows=105 width=364)
Sort Key: p.id
-> Merge Right Join (cost=313.35..1342.87 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..6172.49 rows=600 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=313.06..313.32 rows=105 width=356)
Sort Key: p.id
-> Seq Scan on tbl_projects p (cost=0.00..309.54 rows=105 width=356)
Filter: (creator = 1001)
SubPlan 1
-> Aggregate (cost=39.05..39.06 rows=1 width=32)
-> Seq Scan on tbl_invoices i (cost=0.00..39.05 rows=1 width=6)
Filter: (project_id = p.id)