Optimal query pattern to count related entries in PostgreSQL
nested selects  can be slower or be faster depends on how many records are being processed. 

select *, (select count(*) from categories b where a.id=b.parent_id) 
   from categories a


This can be faster or have the same speed if only a few records or with where clause filters this down 

select *, (select count(*) from categories b where a.id=b.parent_id) 
   from categories a  where a.id = 5


A faster solution for all the records would be something like this  

Select categories.*, coalesce(counted, 0) from categories 
   left join ( select parent_id, count(*) as counted from categories group by parent_id) child
   on categories.id = child.parent_id


with this query  planner has an easier time figuring out what to do.  Nested selects the planner has harder time with as it has to treat them as VOLATILE.  meaning it has to keep calling the nested query for each record