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 2020/07/14 09:23:47 UTC
[GitHub] [couchdb] garrensmith commented on issue #2856: $or and $in operators do not seem to be using indices
garrensmith commented on issue #2856:
URL: https://github.com/apache/couchdb/issues/2856#issuecomment-658074431
The `$in` can be used in an index. Say for the example of the index:
```
{
"index": {
"fields": [
"root.input"
]
},
"name": "foo-json-index",
"type": "json"
}
```
With selector:
```
{
selector: {
input.root: "aimer",
input.option: {
$in: ["option1", "option2"]
}
}
}
```
Mango will choose the above index because you have `input.root` in your selector. Then when it reads the docs from the index it will filter them out based on your fields in the `$in` section.
In another case if you had an index like this:
```
{
"index": {
"fields": [
"input.option"
]
},
"name": "foo-json-index",
"type": "json"
}
```
And the same query:
```
{
selector: {
input.root: "aimer",
input.option: {
$in: ["option1", "option2"]
}
}
}
```
Then mango will read everything from the `input.option` index and then filter each document with the full selector.
The better option is to have the first index as it will reduce the number of documents that need to be fetched from the index.
Hope that clears it up a bit more.
----------------------------------------------------------------
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