QUERY PLAN
Subquery Scan on sub (cost=105.03..105.07 rows=1 width=199)
Filter: (sub.id = 1537)
-> WindowAgg (cost=105.03..105.05 rows=1 width=199)
-> Sort (cost=105.03..105.03 rows=1 width=191)
Sort Key: sub_1.status, sub_1.end_at, sub_1.created_at DESC
-> Subquery Scan on sub_1 (cost=105.00..105.02 rows=1 width=191)
-> Group (cost=105.00..105.01 rows=1 width=191)
Group Key: s.id
InitPlan 1 (returns $0)
-> Aggregate (cost=50.97..50.98 rows=1 width=32)
-> Seq Scan on tbl_tasks s_1 (cost=0.00..50.87 rows=38 width=13)
Filter: ((tree_path IS NOT NULL) AND (head_of = 1001) AND (status = '1'::smallint))
-> Sort (cost=54.02..54.03 rows=1 width=191)
Sort Key: s.id
-> Seq Scan on tbl_tasks s (cost=0.00..54.02 rows=1 width=191)
Filter: ((tree_path @> $0) AND (head_of = 1001) AND (status = '1'::smallint))