QUERY PLAN
Sort (cost=7896.91..7897.23 rows=127 width=477)
Sort Key: p.created_at DESC
-> HashAggregate (cost=2332.41..7892.47 rows=127 width=477)
Group Key: p.id
-> Merge Right Join (cost=1253.55..2314.46 rows=1436 width=365)
Merge Cond: (sl.project_id = p.id)
-> Index Scan using tbl_work_logs_project_id_idx on tbl_work_logs sl (cost=0.29..6294.15 rows=35733 width=12)
-> Sort (cost=1253.26..1253.58 rows=127 width=357)
Sort Key: p.id
-> Merge Right Join (cost=190.23..1248.82 rows=127 width=357)
Merge Cond: (arrive.project_id = p.id)
-> Index Scan using tbl_work_logs_project_id_idx on tbl_work_logs arrive (cost=0.29..6383.48 rows=682 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=189.94..190.26 rows=127 width=349)
Sort Key: p.id
-> Seq Scan on tbl_projects p (cost=0.00..185.50 rows=127 width=349)
Filter: (creator = 1001)
SubPlan 1
-> Aggregate (cost=43.72..43.73 rows=1 width=32)
-> Seq Scan on tbl_invoices i (cost=0.00..43.71 rows=1 width=6)
Filter: (project_id = p.id)