Avoid recalculating whether the relationship is a self join.
Process query only when needed.
Be consistent with the result set variable name.