QUERY PLAN
Aggregate (cost=34.10..34.11 rows=1 width=8)
-> Sort (cost=33.98..34.00 rows=8 width=222)
Sort Key: s.created_at DESC
-> HashAggregate (cost=33.78..33.86 rows=8 width=222)
Group Key: s.id
-> Hash Right Join (cost=23.51..33.36 rows=169 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.99..22.99 rows=42 width=12)
-> Nested Loop (cost=5.39..22.99 rows=42 width=12)
-> Index Scan using tbl_users_pkey on tbl_users u (cost=0.14..8.16 rows=1 width=4)
Index Cond: (id = 1001)
Filter: (department_id = 4)
-> Hash Right Join (cost=5.25..14.40 rows=42 width=16)
Hash Cond: (turs.task_group_id = s.id)
-> Seq Scan on tbl_task_group_user_relationships turs (cost=0.00..7.83 rows=483 width=4)
-> Hash (cost=5.15..5.15 rows=8 width=20)
-> Seq Scan on tbl_task_groups s (cost=0.00..5.15 rows=8 width=20)
Filter: (head_of = 1001)