QUERY PLAN
Sort (cost=7246.96..7247.28 rows=128 width=477)
Sort Key: p.created_at DESC
-> HashAggregate (cost=1638.64..7242.48 rows=128 width=477)
Group Key: p.id
-> Merge Right Join (cost=559.76..1620.67 rows=1437 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=559.47..559.79 rows=128 width=357)
Sort Key: p.id
-> Merge Right Join (cost=191.53..554.99 rows=128 width=357)
Merge Cond: (arrive.project_id = p.id)
-> Index Only Scan using tbl_work_logs_arrive_project_end_at_idx on tbl_work_logs arrive (cost=0.28..2188.00 rows=682 width=12)
-> Sort (cost=191.25..191.57 rows=128 width=349)
Sort Key: p.id
-> Seq Scan on tbl_projects p (cost=0.00..186.78 rows=128 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)