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 2019/10/07 09:59:19 UTC

[GitHub] [couchdb] garrensmith commented on issue #2236: Mango queries is fake?

garrensmith commented on issue #2236: Mango queries is fake?
URL: https://github.com/apache/couchdb/issues/2236#issuecomment-538928959
 
 
   Before I actually answer this ticket, I need to say that this is **not** how to open a ticket and request help. I can hear you are frustrated, but you don't need to write an angry ticket like this. It is poor form, insulting and honestly I still can't believe I'm going to offer some help. In all likely hood, you are using CouchDB for free. It costs you nothing. It would also cost you nothing to ask for some help politely.
   
   Ok now to your problem, firstly you need to think about how mango works. Internally it is using a map/reduce index. So it builds up a view using your specified `arr_test`. So if you had multiple fields in the array the index would look like roughly like this:
   
   ```
   [a, b, c]
   [a, b, c, d],
   [b, c, d]
   [c, d]
   ```
   
   So now, when you create a selector with `$elemMatch` to query the index. The mango query runner needs to find a way to query the index. The way to make a query fast is to have a startkey/endkey or an equal. Then it can reduce the number of documents it needs to fetch from an index. In your case, `$elemMatch` means *any* item in the array that matches. So if we had a selector like `$elemMatch: c`. We cannot build a startkey/endkey out of it because we don't know where in the array `c` for each item. So CouchDB needs to fetch every document in the index, check if it has the element in the array and then return it if it matches. 
   
   Secondly, you state your environment is Docker on windows. Saying it takes 2 minutes in that setup is not a good way to benchmark. That environment will always be a fair bit slower than a production machine. Also was it 2 minutes the first time or after every time you queried it? The first time you run a query with an index, it will build the index which could explain for it being a little slow.
   
   Hope that helps.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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