QUERY PLAN
Sort (cost=5610.00..5610.26 rows=106 width=486)
Sort Key: p.created_at DESC
-> HashAggregate (cost=1715.70..5606.43 rows=106 width=486)
Group Key: p.id
-> Merge Right Join (cost=690.10..1699.81 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=689.81..690.07 rows=106 width=366)
Sort Key: p.id
-> Nested Loop Left Join (cost=128.66..686.24 rows=106 width=366)
-> Hash Left Join (cost=128.37..298.71 rows=106 width=362)
Hash Cond: (p.client_id = c.id)
-> Seq Scan on tbl_projects p (cost=0.00..170.06 rows=106 width=358)
Filter: (creator = 1001)
-> Hash (cost=104.83..104.83 rows=1883 width=4)
-> Seq Scan on tbl_clients c (cost=0.00..104.83 rows=1883 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=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)