QUERY PLAN
Aggregate (cost=44.71..44.72 rows=1 width=8)
-> Sort (cost=44.44..44.48 rows=18 width=160)
Sort Key: s.status, s.target_completed_at DESC, s.updated_at DESC
-> Group (cost=43.93..44.06 rows=18 width=160)
Group Key: s.id, u.id
-> Sort (cost=43.93..43.97 rows=18 width=26)
Sort Key: s.id
-> Nested Loop (cost=0.00..43.55 rows=18 width=26)
-> Seq Scan on tbl_users u (cost=0.00..8.09 rows=1 width=4)
Filter: ((id = 1001) AND (department_id = 4))
-> Seq Scan on tbl_tasks s (cost=0.00..35.29 rows=18 width=34)
Filter: (head_of = 1001)