5 ms·
That was my thought, but the query is not simple to get the list in order. Plus inserts also require an update.
by rileymat2 6y ago
That was my thought, but the query is not simple to get the list in order. Plus inserts also require an update.
- zzzeek 6y agoIf your application only needs to deal with the list as a whole, then this doesn't matter, you load it in and build the linked list in memory using a hash lookup. Or as someone else mentioned recursive CTEs can do it too but for something small I'd just load it in and be done with it. This article is really overthinking things for the typical real world case.
- gregoriol 6y agoRebuilding a linked list can be very expansive compared to a SELECT * ORDER BY position;
- rileymat2 6y agoI largely agree with everything you said. I thought the point of the article is it just interesting that sql seems well suited for lists, and has primitives for ordering but that within sql alone a performant ordered list is more complicated than one would expect before thinking. Why the constraint on sql alone? In many reporting systems you can generate reports based on an sql query, so a query that pulls out the data in order can be useful in a real world use case.