You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's a common use case (as soon as you paginate things), so it would be nice if we wouldn't have to sort the whole table to get the maximum (or the top k) elements.
It was mentionned on this issue, but it's not really what it is about: #159
It's also mentionned in #1174 but there is no issue linked to it
I actually don't think we should do this. For one thing it really doesn't make this operation enough faster that it changes the scale at which you can use it. It saves storing the objects in memory and transferring all of them over the network (which is a significant savings). But you still have to read every single document off disk which is slow enough that you still won't be able to use this at scale. However this will scale if you use:
and I think it's a much better policy to tell people to just use an index for efficient order_by. The other big reason is that this is actually incredibly difficult to implement on the backend (FRTAFTN&O) and I think it's going to be a long time (post 2.0) before we want to spend developer time on an optimization that's a substantially less efficient than an alternative that already exists. The only argument I could see for this is that it saves you having to use extra space for an index but I'd much rather spend the time fixing that problem than working around it.
In general for optimizations I think we should limit ourselves to the 2 ends of the spectrum and try to avoid the middle ground as much as possible. I see a lot of value in having an inefficient way for people to do things when they're just playing around with the product (in memory order_by) and I see a lot of value in having the efficient solution which is maximally efficient algorithmically. However I think if we start mucking about in solutions that are a bit more efficient than an alternative but not as efficient as the best one we'll:
waste a lot of dev time
make the backend more complicated
make the language more complicated and harder to understand the best practices
Complexity with an index is k log n where n is the number of documents in the database. While the best we could do without an index is n log k which still isn't going to scale to big tables.
Activity
jdoliner commentedon Jul 27, 2013
I actually don't think we should do this. For one thing it really doesn't make this operation enough faster that it changes the scale at which you can use it. It saves storing the objects in memory and transferring all of them over the network (which is a significant savings). But you still have to read every single document off disk which is slow enough that you still won't be able to use this at scale. However this will scale if you use:
and I think it's a much better policy to tell people to just use an index for efficient order_by. The other big reason is that this is actually incredibly difficult to implement on the backend (FRTAFTN&O) and I think it's going to be a long time (post 2.0) before we want to spend developer time on an optimization that's a substantially less efficient than an alternative that already exists. The only argument I could see for this is that it saves you having to use extra space for an index but I'd much rather spend the time fixing that problem than working around it.
In general for optimizations I think we should limit ourselves to the 2 ends of the spectrum and try to avoid the middle ground as much as possible. I see a lot of value in having an inefficient way for people to do things when they're just playing around with the product (in memory
order_by) and I see a lot of value in having the efficient solution which is maximally efficient algorithmically. However I think if we start mucking about in solutions that are a bit more efficient than an alternative but not as efficient as the best one we'll:neumino commentedon Jul 27, 2013
Oh, maybe I didn't really understand what was going on #159
I thought it was just to let people sort tables with more than one million documents.
If I do create an index and do
What's the complexity of the query?
jdoliner commentedon Jul 29, 2013
Complexity with an index is
k log nwherenis the number of documents in the database. While the best we could do without an index isn log kwhich still isn't going to scale to big tables.neumino commentedon Jul 29, 2013
Oh, that's cool. Should we close this issue then?
jdoliner commentedon Jul 29, 2013
As long as your satisfied that indexes would be a good solution close away.