Description
Currently if two or more indexes are able to be used for a query the choose_best_index can get in a position where it will chose the index based based on sort order of its dbname, ddocid. This isn't ideal.
If we have two docs like this:
doc1 = {
name: "Mary"
};
doc2 = {
name: "Mary",
role: "Ceo"
};
If we create two indexes:
Index 1 = fields: ['name', 'role']
Index 2 = fields: ['name']
And if we create a query like this:
selector: {
name: 'Mary'
};
If index 1 has a ddocId higher in the alphabet e.g A and Index 2 has a lower ddocId like Z. Then Index will be selected which means that doc 1 will be excluded.
An example of a test case can be found here
https://github.com/apache/couchdb/blob/7951c8ae498e372d0db19887c6e39a91885df4e1/src/mango/test/12-use-correct-index.py