Couch ignores use_index, and Pouch errors on use_index, and they both are choosing different indexes by default
- Dominant language
- JavaScript
- Stars
- 17.6k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
### Issue
CouchDb and PouchDb choose different indexes for a `_find` query that does not specify any index.
Is any of this to be expected, or am I doing something wrong? Thanks in advance.
And when trying to force `use_index`, Couch ignores it and Pouch errors. Seems like ignoring is the better route?
### Info
- For pouch, using `pouchdb-node` 8,0.1
- Platform: Chrome
- Server: Both CouchDB 3.3.3 and PouchDB 8.0.1
### Reproduce
Use the above server versions and a TypeScript client that uses http `_find` calls as described below:
I have a `note` document type, that looks like this:
```json
{
"_id": "note:609ed703-ee69-46ec-8be2-4c70d25ad44e",
"_rev": "9-e1f3a3d98d32cbe361bf4ec0665071f9",
"type": "note",
"journal_id": "djrn:c669a908-b345-4ee4-9095-84babc8aea66",
"title": "2024-08-25 note",
"body": "Some text stuff\n",
"created_at": "2024-08-25",
"updated_at": "2024-08-26",
"tags": []
}
```
And when I do a `_find` (by tag matches), using this:
```json
{
"selector": {
"type": {
"$in": [
"note"
]
},
"tags": {
"$in": [
"asdfasdfasdf",
"ddddddddd"
]
}
},
"fields": [
"_id",
"title",
"tags",
"updated_at"
],
}
```
It works fine, but when I use **`_explain`** I see that Couch and Pouch are using different indexes:
- CouchDb is using `type-index` but
- PouchDb is using `tags-index`.
(I tried adding `use_index`, but it seems CouchDb ignores this, and PouchDb errors out (~"could not find the index, or could not use it for this query").
Here is an example of what the indexes look like; they are almost identical in Couch and Pouch:
`type-index` from PouchDb (same index is in Couch, except for id, rev):
```json
{
"_id": "_design/idx-bae76d56ce6ab639848d59c2a1d8b364",
"language": "query",
"views": {
"type-index": {
"map": {
"fields": {
"type": "asc"
}
},
"reduce": "_count",
"options": {
"def": {
"fields": [
"type"
]
}
}
}
},
"_rev": "1-dd74d6c53ea6e913934d836695512a07"
}
```
`tags-index` from CouchDb (same index is in Pouch, except for id, rev):
```json
{
"_id": "_design/723268ced4323d1b517d25ade1287381c0147cef",
"_rev": "1-cc3ee54469dd17f10c535366c2e1f972",
"language": "query",
"views": {
"tags-index": {
"map": {
"fields": {
"tags": "asc"
},
"partial_filter_selector": {}
},
"reduce": "_count",
"options": {
"def": {
"fields": [
"tags"
]
}
}
}
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.