Skip to content

$in operator is in-efficient #3251

Answered by kocolosk
wildersachin asked this question in Q&A
Discussion options

You must be logged in to vote

Hiya, the CouchDB query planner has room for improvement here. Take a look at the indexable_fields function:

https://github.com/apache/couchdb/blob/3.1.1/src/mango/src/mango_idx_view.erl#L252-L312

Currently it does not try to satisfy $in or $or operators using an index, so it's returning everything with docType: data and then filtering at query time. One could certainly imagine improving the planner so it performs multiple point lookups in the index, one for each element of your $in array, but that's not present today. Some possible workarounds:

  1. Submit multiple queries in parallel, one for each dataId and then combine the results in your app
  2. Define a view keyed on [ "docType", "dataId" ]

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by wildersachin
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #3251 on November 08, 2020 15:52.