QUERY PLAN
Sort (cost=6109.95..6110.21 rows=106 width=486)
Sort Key: p.created_at DESC
-> HashAggregate (cost=2215.65..6106.38 rows=106 width=486)
Group Key: p.id
-> Merge Right Join (cost=1190.05..2199.76 rows=1271 width=374)
Merge Cond: (sl.project_id = p.id)
-> Index Scan using tbl_work_logs_project_id_idx on tbl_work_logs sl (cost=0.29..5952.71 rows=33645 width=12)
-> Sort (cost=1189.76..1190.02 rows=106 width=366)
Sort Key: p.id
-> Merge Right Join (cost=173.92..1186.19 rows=106 width=366)
Merge Cond: (arrive.project_id = p.id)
-> Index Scan using tbl_work_logs_project_id_idx on tbl_work_logs arrive (cost=0.29..6036.82 rows=561 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=173.63..173.89 rows=106 width=358)
Sort Key: p.id
-> Seq Scan on tbl_projects p (cost=0.00..170.06 rows=106 width=358)
Filter: (creator = 1001)
SubPlan 1
-> Aggregate (cost=36.64..36.65 rows=1 width=32)
-> Seq Scan on tbl_invoices i (cost=0.00..36.64 rows=1 width=6)
Filter: (project_id = p.id)