QUERY PLAN
Aggregate (cost=33.33..33.34 rows=1 width=8)
-> Sort (cost=32.34..32.51 rows=66 width=222)
Sort Key: s.created_at DESC
-> HashAggregate (cost=29.69..30.35 rows=66 width=222)
Group Key: s.id
-> Hash Right Join (cost=19.08..29.52 rows=66 width=12)
Hash Cond: (turs.task_group_id = s.id)
-> Seq Scan on tbl_task_group_user_relationships turs (cost=0.00..7.94 rows=494 width=4)
-> Hash (cost=18.93..18.93 rows=12 width=12)
-> Hash Right Join (cost=14.15..18.93 rows=12 width=12)
Hash Cond: (thrs.task_group_id = s.id)
-> Seq Scan on tbl_task_group_head_of_relationships thrs (cost=0.00..3.93 rows=193 width=4)
-> Hash (cost=14.07..14.07 rows=6 width=12)
-> Hash Join (cost=7.91..14.07 rows=6 width=12)
Hash Cond: (s.head_of = u.id)
-> Seq Scan on tbl_task_groups s (cost=0.00..5.91 rows=91 width=20)
-> Hash (cost=7.80..7.80 rows=9 width=4)
-> Seq Scan on tbl_users u (cost=0.00..7.80 rows=9 width=4)
Filter: (department_id = 9)