QUERY PLAN
Aggregate (cost=38.44..38.45 rows=1 width=8)
-> Sort (cost=38.42..38.43 rows=1 width=218)
Sort Key: s.created_at DESC
-> Group (cost=38.41..38.41 rows=1 width=218)
Group Key: s.id
-> Sort (cost=38.41..38.41 rows=1 width=12)
Sort Key: s.id
-> Hash Join (cost=29.19..38.40 rows=1 width=12)
Hash Cond: (turs.task_group_id = s.id)
-> Seq Scan on tbl_task_group_user_relationships turs (cost=0.00..9.04 rows=42 width=4)
Filter: (user_id = 1000)
-> Hash (cost=29.17..29.17 rows=2 width=12)
-> Hash Right Join (cost=22.06..29.17 rows=2 width=12)
Hash Cond: (thrs.task_group_id = s.id)
-> Seq Scan on tbl_task_group_head_of_relationships thrs (cost=0.00..5.70 rows=370 width=4)
-> Hash (cost=22.05..22.05 rows=1 width=12)
-> Hash Join (cost=16.81..22.05 rows=1 width=12)
Hash Cond: (s.head_of = u.id)
-> Seq Scan on tbl_task_groups s (cost=0.00..5.06 rows=65 width=20)
Filter: (status = '1'::smallint)
-> Hash (cost=16.80..16.80 rows=1 width=4)
-> Seq Scan on tbl_users u (cost=0.00..16.80 rows=1 width=4)
Filter: (department_id = 7)