Optimizing Recursive Queries in SQL