SQLite Forum

Recursive query to find the shortest path
Login
That is correct.  A recursive query is an exhaustive search and barring artificial restrictions (such as LIMIT) will only exit once the recursion is exhausted.  Unlike programmatic recursion, there is no way to "prune" branches based on what you have already found.

In other words, if you take, for example, map routing software searching for a route from point A to point B.  The correct approach is not to LIMIT the number of steps in the recursion but to prohibit further searching of branches that are "too long", where you compute "too long" before asking the question.  It may be, for example, that your search defines "too long" as a path distance more than X times the "as the crow flies" distance between point A and point B.  If this does not generate a useful answer, then increase X.  Lather rinse and repeat until an acceptable solution is found (or the search has taken so long in elapsed time that you can declare that you cannot get there from here).