apache / apache/couchdb

Query all document (_all_docs) from specific partition with filtering returns wrong total_rows value and document information

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

Description

[NOTE]: # ( ^^ Provide a general summary of the issue in the title above. ^^ )

## Description

[NOTE]: # ( Describe the problem you're encountering. )
[TIP]: # ( Do NOT give us access or passwords to your actual CouchDB! )
During the usage of `POST /{db}/_partition/{partition_key}/_all_docs` in the response there is a field `total_rows` and its value should return the number of documents in the shard range hosting that partition.
Furthermore it should return only partition specific documents.

If there is `keys` filter included in the query, currently the request returns the number of documents in the database and all partition related document that matches with the filter. There is no partition filtering.

## Steps to Reproduce
[NOTE]: # ( Include commands to reproduce, if possible. curl is preferred. )
1. Create a partitioned database
2. Create sample partitioned documents
3. Query the database with endpoint: `POST /{db}/_partition/{partition_key}/_all_docs --data-raw {}` It shall return a `total_rows` value. Let's call it `n`.
Returns all partition specific document.
4. Query the database with an additional filter. eg: `POST /{db}/_partition/part2/_all_docs --data-raw {"keys":["part1:doc1", "part2:doc1"]}`
In this case the `total_rows` of the response contains the number of all document of the database .

In the request the following can be seen:
```
"rows": [
{
"id": "part1:doc1",
"key": "part1:doc1",
"value": {
"rev": "5-aa9d2b82de6db1e61fba8e4057299d21"
}
},
{
"id": "part2:doc1",
"key": "part2:doc1",
"value": {
"rev": "3-a707bb62c86bd430389e4d596aeb6084"
}
}
]
```

## Expected Behaviour
The `total_rows` field should have value `n`.
Only partition specific document information should be returned.
This should be the expected response:
```
"rows": [
{
"key": "part1:doc1",
"error": "not_found"
},
"id": "part2:doc1",
"key": "part2:doc1",
"value": {
"rev": "3-a707bb62c86bd430389e4d596aeb6084"
}
]
```
[NOTE]: # ( Tell us what you expected to happen. )

## Your Environment

[TIP]: # ( Include as many relevant details about your environment as possible. )
[TIP]: # ( You can paste the output of curl http://YOUR-COUCHDB:5984/ here. )

* CouchDB version used: CouchDB 3.0.0-6d432a9
* Browser name and version: PostMan 7.15.0
* Operating system and version: MacOS desktop Catalina 10.15.2

## Additional Context

[TIP]: # ( Add any other context about the problem here. )

Contributor guide

Open the contributing guide

Research direction

Start by reproducing POST /{db}/_partition/{partition_key}/_all_docs with and without the keys filter, using the part1 and part2 examples in the issue. Trace the Erlang implementation for this partitioned _all_docs endpoint; the payload names no source files or tests. Done means total_rows remains partition-scoped and rows outside the requested partition are returned as not_found.

Written by the indexing model from the issue text.

Assessment

Tech stack
erlang
Domain
api, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.