QUERY PLAN
Aggregate (cost=97.42..97.44 rows=1 width=8)
-> Sort (cost=97.41..97.41 rows=1 width=224)
Sort Key: s.end_at, s.created_at DESC
InitPlan 1 (returns $0)
-> Aggregate (cost=48.53..48.54 rows=1 width=32)
-> Seq Scan on tbl_tasks s_1 (cost=0.00..45.86 rows=1068 width=13)
Filter: ((tree_path IS NOT NULL) AND (status = '1'::smallint))
-> Group (cost=48.84..48.85 rows=1 width=224)
Group Key: s.id
-> Sort (cost=48.84..48.85 rows=1 width=18)
Sort Key: s.id
-> Seq Scan on tbl_tasks s (cost=0.00..48.84 rows=1 width=18)
Filter: ((parent_id IS NULL) AND (tree_path @> $0) AND (status = '1'::smallint))