QUERY PLAN
Sort (cost=6685.33..6685.61 rows=111 width=484)
Sort Key: p.created_at DESC
-> HashAggregate (cost=2324.25..6681.56 rows=111 width=484)
Group Key: p.id
-> Merge Right Join (cost=1280.79..2307.95 rows=1304 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=1280.50..1280.78 rows=111 width=364)
Sort Key: p.id
-> Merge Right Join (cost=246.74..1276.73 rows=111 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=246.45..246.72 rows=111 width=356)
Sort Key: p.id
-> Seq Scan on tbl_projects p (cost=0.00..242.68 rows=111 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)