QUERY PLAN
Limit (cost=51.53..51.53 rows=1 width=149)
-> Sort (cost=51.53..51.53 rows=1 width=149)
Sort Key: s.target_completed_at, s.updated_at DESC
-> Group (cost=51.51..51.52 rows=1 width=149)
Group Key: s.id, u.id
-> Sort (cost=51.51..51.51 rows=1 width=149)
Sort Key: s.id
-> Nested Loop (cost=0.00..51.50 rows=1 width=149)
-> Seq Scan on tbl_tasks s (cost=0.00..43.37 rows=1 width=145)
Filter: ((head_of = 1001) AND (status = '0'::smallint))
-> Seq Scan on tbl_users u (cost=0.00..8.12 rows=1 width=4)
Filter: ((id = 1001) AND (department_id = 10))