Optimise count_parents()

This combines two queries using a union that already does distinct.

This also removes the distinct from the parents() function because it
uses a union which is supposed to use distinct already.