3 ms·
The best you can do is slap an index -- at the end of the day, as the parent said, you're traversing a linked list in random order which means that if your data
by matthewaveryusa 8y ago
The best you can do is slap an index -- at the end of the day, as the parent said, you're traversing a linked list in random order which means that if your database index doesn't fit in RAM you'll be doing a random disk access per recursive step. Slow, but no slower than any other solution with that same problem.
If you want to optimize such a query, go back to the drawing board and see if your data truly warrants a recursive random walk.