apache / apache/couchdb

Mango: do not warn about missing index when only _id is being selected against

Open
#2,124 3 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Erlang
Stars
7k
Forks
1.1k
Avg merge
1d 16h
Merged PRs (30d)
9

Description

## 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 correct `start_key` and `end_key`):

```
{
"selector": {
"$and": [
{
"_id": {
"$gt": "bar"
}
},
{
"_id": {
"$lt": "foo"
}
}
]
}
}
```

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 request `execution_stats`.

## Expected Behaviour

No warning.

## Your Environment

* CouchDB Version used: 2.3.0
* Operating System and version: Linux (Docker container)

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the selector against the `_find` endpoint with `execution_stats`, and inspect how Mango handles `_id` range queries and the `_all_docs` index when producing warnings. Done means the query still uses the `_id` index and no longer reports a missing-index warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
erlang
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.