QUERY PLAN
Sort (cost=6733.13..6733.41 rows=113 width=477)
Sort Key: p.created_at DESC
-> HashAggregate (cost=1792.02..6729.27 rows=113 width=477)
Group Key: p.id
-> Merge Right Join (cost=739.34..1776.07 rows=1276 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..6291.82 rows=35731 width=12)
-> Sort (cost=739.05..739.34 rows=113 width=357)
Sort Key: p.id
-> Nested Loop Left Join (cost=135.58..735.20 rows=113 width=357)
-> Hash Left Join (cost=135.29..321.14 rows=113 width=353)
Hash Cond: (p.client_id = c.id)
-> Seq Scan on tbl_projects p (cost=0.00..185.55 rows=113 width=349)
Filter: (creator = 1001)
-> Hash (cost=110.13..110.13 rows=2013 width=4)
-> Seq Scan on tbl_clients c (cost=0.00..110.13 rows=2013 width=4)
-> Index Scan using tbl_work_logs_client_id_idx on tbl_work_logs arrive (cost=0.29..3.65 rows=1 width=12)
Index Cond: ((client_id = c.id) AND (client_id IS NOT NULL))
Filter: ((NOT is_draft) AND (location_in_id IS NOT NULL) AND (location_out_id IS NOT NULL) AND (scenario_id = 1))
SubPlan 1
-> Aggregate (cost=43.63..43.64 rows=1 width=32)
-> Seq Scan on tbl_invoices i (cost=0.00..43.62 rows=1 width=6)
Filter: (project_id = p.id)