UUID/GUID field and shards
There is no elegant way to proceed. If the hierarchy has an unknown amount of levels, you can't serialize it into fixed relations. But partitioning it is probably a bad idea. Perhaps you want a Graph Database?