You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/08/08 23:11:22 UTC
[GitHub] wohali commented on issue #1549: Slow `_find` query when no
documents match selector
wohali commented on issue #1549: Slow `_find` query when no documents match selector
URL: https://github.com/apache/couchdb/issues/1549#issuecomment-411582890
Hi @CWX-iggy, thanks for your issue.
Unfortunately, you need to know that the `$in` operator has to do a full scan on every query on every document in the index. This cannot be pre-determined given the way Mango builds indexes. Mango will index the full contents of the field you are searching on (here, `league`) but has to at query time do a manual comparison of the contents of that index, per-document, with your parameters at query time. You will experience similar poor performance with other inexact operators, such as the `$regex` operator. @tonysun83 can you confirm my understanding of Mango indexing here?
I agree this is not clearly called out in the documentation, and for that I apologise. Would you agree with me converting your issue to one that would let us improve our documentation on this point?
Your choices to improve performance are to use [Mango partial indexing](http://docs.couchdb.org/en/2.2.0/api/database/find.html#partial-indexes) to reduce the number of documents in your index (best option), use `$eq` or another _exact_ operator instead of `$in` (next best, but you may not be able to capture your query, or try something like Clouseau/Dreyfus for full text search capability instead (hardest to set up, requires JDK6 and Apache Lucene, but is more flexible in terms of partial term searching). This last option lets you use text-based Mango indexes if you want to stay with Mango.
I recommend starting with partial indexing. You can use this to make multiple sub-indexes that reduce the likelihood of few documents being found. Partial indexes are especially good to filter documents by type, for which it looks like your `meta.type` or `league` fields might be good candidates. You may even find that running 2 mango queries (for instance, across 2 `league`s) across 2 partial indexes and then merging the results in your client / app layers will be faster than running the single query across the entire content database.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services