big-r81 commented on issue #3998:
URL: https://github.com/apache/couchdb/issues/3998#issuecomment-1102812121
I think the answer is much simpler:
There is a special defualt index only for `_id` which is for me:
```json
{
"total_rows": 2,
"indexes": [
{
"ddoc": null,
"name": "_all_docs",
"type": "special",
"def": { "fields": [{ "_id": "asc" }] }
},
{
"ddoc": "_design/c3f8e5d6df2ef807ee1016949098ac4e6287d31c",
"name": "tags-json-index",
"type": "json",
"partitioned": false,
"def": { "fields": [{ "_id": "asc" }, { "shri": "asc" }] }
}
]
}
```
If I only sort for `_id` the "special" index is used. If I use
```json
"sort" : ["_id", "shri"]
```
in the query, with the following ddoc
```json
{
"_id": "_design/c3f8e5d6df2ef807ee1016949098ac4e6287d31c",
"_rev": "3-bbb25abe2218156af2ad8a5d6648ce1d",
"language": "query",
"views": {
"tags-json-index": {
"map": {
"fields": {
"_id": "asc",
"shri": "asc"
},
"partial_filter_selector": {}
},
"reduce": "_count",
"options": {
"def": {
"fields": [
"_id",
"shri"
]
}
}
}
}
}
```
then the the mango query uses this index...
```json
{
"dbname": "test",
"index": {
"ddoc": "_design/c3f8e5d6df2ef807ee1016949098ac4e6287d31c",
"name": "tags-json-index",
"type": "json",
"partitioned": false,
"def": {
"fields": [
{
"_id": "asc"
},
{
"shri": "asc"
}
]
}
},
"partitioned": false,
"selector": {
"$and": [
{
"shri.tags": {
"$elemMatch": {
"": {
"$eq": "java"
}
}
}
},
{
"_id": {
"$gte": "0"
}
}
]
},
"opts": {
"use_index": [],
"bookmark": "nil",
"limit": 501,
"skip": 0,
"sort": {
"_id": "asc",
"shri": "asc"
},
"fields": [
"_id"
],
"partition": "",
"r": [
49
],
"conflicts": false,
"stale": false,
"update": true,
"stable": false,
"execution_stats": false
},
"limit": 501,
"skip": 0,
"fields": [
"_id"
],
"mrargs": {
"include_docs": true,
"view_type": "map",
"reduce": false,
"partition": null,
"start_key": [
"0"
],
"end_key": [
"<MAX>"
],
"direction": "fwd",
"stable": false,
"update": true,
"conflicts": "undefined"
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]