QUERY PLAN
Sort (cost=771.44..771.46 rows=8 width=483)
Sort Key: p.created_at DESC
-> GroupAggregate (cost=453.79..771.32 rows=8 width=483)
Group Key: p.id
-> Sort (cost=453.79..454.02 rows=93 width=371)
Sort Key: p.id
-> Nested Loop Left Join (cost=4.90..450.75 rows=93 width=371)
-> Nested Loop Left Join (cost=0.57..262.61 rows=8 width=363)
-> Nested Loop Left Join (cost=0.28..233.47 rows=8 width=359)
-> Seq Scan on tbl_projects p (cost=0.00..175.10 rows=8 width=355)
Filter: (creator = 1000)
-> Index Only Scan using tbl_clients_pkey on tbl_clients c (cost=0.28..7.29 rows=1 width=4)
Index Cond: (id = p.client_id)
-> Index Scan using tbl_work_logs_client_id_idx on tbl_work_logs arrive (cost=0.29..3.63 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))
-> Bitmap Heap Scan on tbl_work_logs sl (cost=4.33..23.47 rows=5 width=12)
Recheck Cond: (project_id = p.id)
-> Bitmap Index Scan on tbl_work_logs_project_id_idx (cost=0.00..4.33 rows=5 width=0)
Index Cond: (project_id = p.id)
SubPlan 1
-> Aggregate (cost=39.45..39.46 rows=1 width=32)
-> Seq Scan on tbl_invoices i (cost=0.00..39.45 rows=1 width=6)
Filter: (project_id = p.id)