duplicate entries in keys gives incorrect order
- Dominant language
- Erlang
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 9
Description
## Description
When querying a custom view with duplicate entries in the `keys` parameter the output will be ordered incorrectly.
_all_docs works correctly and so does Cloudant apparantly (did not test that myself), but custom view does not keep the order given in `keys`
## Steps to Reproduce
View:
```json
{
"_id": "_design/personen",
"_rev": "6-a0208565e54d1d300dcee98f489ae15b",
"views": {
"actief": {
"map": "function (doc) {\n if (doc._id.substr(0, \"persoon_2_\".length) == \"persoon_2_\" && doc.data && doc.data.actief) {\n emit(doc._id.substr(\"persoon_2_\".length), 1);\n }\n}"
}
},
"language": "javascript"
}
```
`curl -gi 'http://server:5984/db/_design/personen/_view/actief?keys=[%2210003%22,%2210002%22,%2210003%22]'`
```
Cache-Control: must-revalidate
Content-Type: application/json
Date: Tue, 27 Aug 2019 10:26:34 GMT
Server: CouchDB/2.3.1 (Erlang OTP/19)
Transfer-Encoding: chunked
X-Couch-Request-ID: 98e58c6382
X-CouchDB-Body-Time: 0
{"total_rows":13933,"offset":2,"rows":[
{"id":"persoon_2_10002","key":"10002","value":1},
{"id":"persoon_2_10003","key":"10003","value":1},
{"id":"persoon_2_10003","key":"10003","value":1}
```
## Expected Behaviour
Order should be same as the input to `keys`
```{"total_rows":13933,"offset":2,"rows":[
{"id":"persoon_2_10003","key":"10003","value":1},
{"id":"persoon_2_10002","key":"10002","value":1},
{"id":"persoon_2_10003","key":"10003","value":1}
```
## Your Environment
Tested on Windows with 2.2.0 and 2.3.1 and on Linux with 2.3.1
## Additional context
Discussed with @rnewson on (web)irc, who could reproduce it locally but not on Cloudant
https://gist.github.com/rnewson/14a8175a295017ddf5d772331ea445c5
Contributor guide
Research direction
Reproduce the custom-view request with the provided curl command, comparing its duplicate-key ordering with _all_docs and the expected response. Trace the custom-view handling of the keys parameter; done means preserving the input order, including repeated keys, and adding regression coverage for this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- erlang, javascript
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100