IMHO fixing this is more a job for the query planner/optimizer than for the SQL language itself. I wonder if there's a more general optimization that would help with this and other similar graph-related tasks...
Generalized graph traversals require each query to have additional data structures that grow with table size. This becomes an expensive proposition as tables get large, especially if you have many concurrent queries. Some databases designed for graph processing have internals and storage models that make it more efficient to resource manage this extra state. A SQL database, which has other priorities, would not implement this.