linquize opened a new issue #1371: Mango index not used when selector has a field with "$gt", "$lt" and another field URL: https://github.com/apache/couchdb/issues/1371 <!--- Provide a general summary of the issue in the Title above --> Write a Mango query with 2 selector fields. One field "a" checks "$gt", "$lt" and anther field "b" simply checks equality. Create index of one field ["a"] and these 2 fields ["a", "b"]. ## Expected Behavior <!--- If you're describing a bug, tell us what should happen --> <!--- If you're suggesting a change/improvement, tell us how it should work --> For all Mango queries below, Mango index `a-index` is used. ## Current Behavior <!--- If describing a bug, tell us what happens instead of the expected behavior --> <!--- If suggesting a change/improvement, explain the difference from current behavior --> For Mango query 1, Mango index `a-index` is not used. For Mango query 2 and 3, Mango index `a-index` is used. ## Possible Solution <!--- Not obligatory, but suggest a fix/reason for the bug, --> <!--- or ideas how to implement the addition or change --> Fix the bug. ## Steps to Reproduce (for bugs) <!--- Provide a link to a live example, or an unambiguous set of steps to --> <!--- reproduce this bug. Include code to reproduce, if relevant --> **Bulk Insert Documents** ```json { "docs": [ { "a": "1970-01-01", "b": 1, "c": "xxx" }, { "a": "1970-01-02", "b": 2, "c": "yyy" }, { "a": "1970-01-03", "b": 1, "c": "zzz" }, ] } ``` **Query 1** ```json { "selector": { "a": { "$gte": "1970-01-01", "$lt": "1970-01-31" }, "b": 1 } } ``` **Query 2** ```json { "selector": { "a": { "$gte": "1970-01-01", "$lt": "1970-01-31" } } } ``` **Query 3** ```json { "selector": { "a": { "$gte": "1970-01-01" }, "b": 1 } } ``` **Index 1** ```json { "index": { "fields": [ "a" ] }, "name": "a-index", "type": "json" } ``` **Index 2** ```json { "index": { "fields": [ "a", "b" ] }, "name": "a-b-index", "type": "json" } ``` 1. Bulk insert documents as above 2. Open Fauxton 3. Create Mango index 1 as above 4. Enter Mango query 1 as above 5. Press Explain button 6. I found that index `a-index` is not used 7. Run the query, it is really slow 8. Enter Mango query 2 or query 3 as above 9. Press Explain button 10. Index `a-index` is used 11. Perform above steps again, but this time, create index 2 ## Context <!--- How has this issue affected you? What are you trying to accomplish? --> <!--- Providing context helps us come up with a solution that is most useful in the real world --> Index `a-index` is not used in the mango query 1, so query performance is poor. ## Your Environment <!--- Include as many relevant details about the environment you experienced the bug in --> * Version used: 2.1.1 (docker image) * Browser Name and version: Firefox 60 * Operating System and version (desktop or mobile): Ubuntu 16.04 x64
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
