Open oliverdain opened 5 years ago
Hi @oliverdain ,
That'll be because the _all_docs
index is what we check to see if no matching index was found. :smile:
It sounds like you'd need a special case for this Mango query where we suppress the warning when only the _id
field is being used.
Out of curiosity, why use the Mango API here instead of just using the /{db}/_all_docs
endpoint?
Hi @wohali . Thanks for the explanation. I've simplified the real query here to make the bug report simpler but the real query used _id
and some other fields to further limit the results I get. Note that with Mango this is legal and if I do that with an index other than _all_docs
I do not get a warning. For example, a query like this is, I think, quite reasonable:
{
"selector": {
"$and": [
{
"_id": {
"$gt": "bar"
}
},
{
"_id": {
"$lt": "foo"
}
},
{
"other_field": "some value"
}
]
}
}
Assuming there aren't too many docs with _id
between bar
and foo
this is a very useful way to use Mango and the performance is quite good.
I think the desired behavior isn't "suppress the warning when only the _id field is being used" but rather something like "suppress the warning when the _id field has significantly reduced the set of documents that must be examined" or whatever the equivalent rule is for a normal Mango index.
Hey @oliverdain , thanks for writing back.
Technically, what you're saying still requires a main index if you don't have a direct index that includes both _id
and other_field
. What I think would be the best compromise here is that the user can safely ignore the warning - but IMO the warning should still be generated. Adding more logic in that part of the code could slow down all requests, something we'd really prefer not to do.
To me, this feels like a documentation callout - if you'd like to open a PR in https://github.com/apache/couchdb-documentation and explain that the warning can be safely ignored in this scenario, I'd be happy to merge that.
Description
If I run the following query it clearly is using the _id index/btree (you can tell by how fast it runs and
explain
shows it's using_all_docs
with the correctstart_key
andend_key
):But when I run it I get "warning": "no matching index found, create an index to optimize query time".
"use_index": "_all_docs"
did not make it go away.Steps to Reproduce
Hit the
_find
endpoint with that selector and requestexecution_stats
.Expected Behaviour
No warning.
Your Environment