In case the only information you got is the ID of the parent, then the only way to get all the ancestors is to iterate get_parent() function, which is evident.
But you can invent more effective structure to speed it up. You should store more information in the table to make it faster.
Say, you're sure that you have no more then 216 categories in every level of hierarchy. Then you can store all the hierarchy in one field, having first two bytes for the top-level ancestor, next two - for its child, and so on down to the current element, and zerofill since.
Then you would be able to retrieve all the hierarchy with one query.