QUERY PLAN
Limit (cost=31.06..31.08 rows=8 width=396)
-> Sort (cost=31.06..31.08 rows=8 width=396)
Sort Key: s.created_at DESC
-> HashAggregate (cost=30.80..30.94 rows=8 width=396)
Group Key: s.id
-> Hash Right Join (cost=19.24..30.57 rows=91 width=372)
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=19.03..19.03 rows=17 width=372)
-> Nested Loop (cost=6.24..19.03 rows=17 width=372)
-> Seq Scan on tbl_users u (cost=0.00..8.16 rows=1 width=4)
Filter: ((id = 1001) AND (department_id = 4))
-> Hash Right Join (cost=6.24..10.70 rows=17 width=372)
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=6.14..6.14 rows=8 width=372)
-> Seq Scan on tbl_task_groups s (cost=0.00..6.14 rows=8 width=372)
Filter: (head_of = 1001)