QUERY PLAN
Sort (cost=51.60..51.61 rows=1 width=794)
Sort Key: p.created_at DESC
-> GroupAggregate (cost=30.46..51.59 rows=1 width=794)
Group Key: p.id
-> Sort (cost=30.46..30.47 rows=4 width=682)
Sort Key: p.id
-> Nested Loop Left Join (cost=8.33..30.42 rows=4 width=682)
-> Nested Loop Left Join (cost=4.16..20.89 rows=1 width=674)
-> Seq Scan on tbl_projects p (cost=0.00..11.38 rows=1 width=666)
Filter: (creator = 5493)
-> Bitmap Heap Scan on tbl_work_logs arrive (cost=4.16..9.51 rows=1 width=12)
Recheck Cond: (project_id = p.id)
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))
-> Bitmap Index Scan on tbl_work_logs_project_id_idx (cost=0.00..4.16 rows=2 width=0)
Index Cond: (project_id = p.id)
-> Bitmap Heap Scan on tbl_work_logs sl (cost=4.16..9.50 rows=2 width=12)
Recheck Cond: (project_id = p.id)
-> Bitmap Index Scan on tbl_work_logs_project_id_idx (cost=0.00..4.16 rows=2 width=0)
Index Cond: (project_id = p.id)
SubPlan 1
-> Aggregate (cost=21.01..21.02 rows=1 width=32)
-> Seq Scan on tbl_invoices i (cost=0.00..21.00 rows=4 width=32)
Filter: (project_id = p.id)