faster than 100%
select id\n,case when p_id is null then \'Root\'\n      when id in (select p_id from tree) then \'Inner\'\n      else \'Leaf\' end as Type\nfrom tree\norder by 
select id\n,case when p_id is null then \'Root\'\n      when id in (select p_id from tree) then \'Inner\'\n      else \'Leaf\' end as Type\nfrom tree\norder by id asc\n;
[]