It seems like that method would be slow. But I’d need more information to know if there is a better solution.
Where is the relationship set and how do they work? The main product? Each of the “variations”? Both? Are you using a relationship field or a post object field?