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
Use a multi index and a mapping function to speed get_all/contains
If your program frequently executes a get_all followed by a contains, that operation can be made more efficient by creating a compound multi index using a mapping function on the field that contains the list.
get(1) should be get_all(1) (otherwise the filter coming after makes no sense)
Assuming get(1) is fixed with get_all(1), if the equipment list has duplicated element, the two queries are not equivalent, unless we add a distinct term on the sindexed query.
As you've noticed, a distinct is not automatically applied behind a getAll or between using a multi index. Doing so would change the memory complexity of such queries, because we would have to keep track of already seen documents (it doesn't matter if you retrieve something like 3 documents, but imagine you do a between and a million documents match the range).
There is one exception, which is querying multi geo indexes through getIntersecting. getIntersecting never returns duplicates (this is possible because the number of results it can produce is limited by the array size limit).
Activity
nviennot commentedon Nov 17, 2014
If RethinkDB does not apply
distinctby itself, the documentation in http://www.rethinkdb.com/docs/secondary-indexes/ruby/ is misleading/wrong:get(1)should beget_all(1)(otherwise the filter coming after makes no sense)get(1)is fixed withget_all(1), if the equipment list has duplicated element, the two queries are not equivalent, unless we add adistinctterm on the sindexed query.danielmewes commentedon Nov 17, 2014
Thanks for letting us know.
As you've noticed, a
distinctis not automatically applied behind agetAllorbetweenusing a multi index. Doing so would change the memory complexity of such queries, because we would have to keep track of already seen documents (it doesn't matter if you retrieve something like 3 documents, but imagine you do abetweenand a million documents match the range).There is one exception, which is querying multi geo indexes through
getIntersecting.getIntersectingnever returns duplicates (this is possible because the number of results it can produce is limited by the array size limit).We will clarify this in the documentation.
danielmewes commentedon Nov 17, 2014
I created rethinkdb/docs#580 for updating the docs. Marking this as moved.