faster than 94.47% (if)
select id, if(isnull(p_id), \'Root\',\n             if(id in (select distinct p_id from tree), \'Inner\', \'Leaf\')) as type\nfrom tree
select id, if(isnull(p_id), \'Root\',\n             if(id in (select distinct p_id from tree), \'Inner\', \'Leaf\')) as type\nfrom tree
[]