The SQL for the second recursive CTE table can be optimized by adding a where condition on the recursive part that rules out users that are not roles. The functionality remains the same as only roles can be granted to users.