QUERY PLAN
Sort (cost=10770.96..10771.50 rows=216 width=484)
Sort Key: p.created_at DESC
-> HashAggregate (cost=2283.51..10762.59 rows=216 width=484)
Group Key: p.id
-> Merge Right Join (cost=1221.47..2251.72 rows=2543 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=1221.18..1221.72 rows=216 width=364)
Sort Key: p.id
-> Merge Right Join (cost=182.25..1212.80 rows=216 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=181.96..182.50 rows=216 width=356)
Sort Key: p.id
-> Seq Scan on tbl_projects p (cost=0.00..173.59 rows=216 width=356)
Filter: (creator = 1004)
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)