I'm playing with Mango queries on a CouchDB 2.0 instance, through the fantastic pouchdb-find.
A few times I got the dreaded no matching index found, create an index to optimize query time
warning even though I was using indexed fields.
Just now I got it when selecting "type": {"$in": ["a", "b"]}
or the equivalent "$or": [{"type": "a"}, {"type": "b"}]
, even though an index on type
exists.
Googling (cloudant query docs, pouchdb-find docs, SO question) didn't help, and in the latter @nlawson says that some predicates ($ne
in the aforementioned question, but maybe my $in
/ $or
fall into the same basket?) "currently do not use any index".
- If I'm indeed in the same boat, what does that mean? Is the impossibility to use indexes on queries using certain predicates a limitation of the mango backend, or a pouchdb one?
- Am I doing something wrong / is there an index workaround to avoid this?
- More generally, is there documentation I could read to get a deeper grip on how indexes work and how to troubleshoot them?
Thanks!
selector: { _id: {"$gt":0}, type: {"$in": ["a", "b"]} }
– Poetrytype
). And adding_id: {"$gt":0}
did the trick oÔ. 1. Can you explain what's going on? 2. Feel free to convert your comment to an answer, I'll accept it. Thanks! – Antecedency_id
trick in this couchdb-user mailing-list thread. Turns out: it's not a way to use an index, quite the contrary: it's only a way to explicitly tell pouchdb-find I know I'll be running without index, because my query won't fit into CouchDB's final map/reduce + composite key-based indexing, thus requiring fetchingallDocs
and doing in-memory filtering. I'll let this settle for a while, and will answer my question with a "no". – Antecedency