wohali commented on 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#issuecomment-394191191
 
 
   This appears to have been fixed on master (which will become the 2.2.0 
release):
   
   ```
   # Create the database and 3 documents
   $ curl -X PUT localhost:15984/db
   {"ok":true}
   $ curl -X PUT localhost:15984/db/1 -d '{ "a": "1970-01-01", "b": 1, "c": 
"xxx" }'
   {"ok":true,"id":"1","rev":"1-5455dc18ba50b873f80d08b786882d75"}
   $ curl -X PUT localhost:15984/db/2 -d '{ "a": "1970-01-02", "b": 2, "c": 
"yyy" }'
   {"ok":true,"id":"2","rev":"1-929563268787e16b961a44c66bc502be"}
   $ curl -X PUT localhost:15984/db/3 -d '{ "a": "1970-01-03", "b": 1, "c": 
"zzz" }'
   {"ok":true,"id":"3","rev":"1-9f54d5b98444b17b4b80497fce915428"}
   $
   
   # Now we create the index
   $ curl -X POST -H "Content-Type: application/json" localhost:15984/db/_index 
-d '{
      "index": {
         "fields": [
            "a"
         ]
      },
      "name": "a-index",
      "type": "json"
   }'
   
{"result":"created","id":"_design/2b836b080d41d5929e6cf097a1364826f34f60bd","name":"a-index"}
   $ curl localhost:15984/db/_design/2b836b080d41d5929e6cf097a1364826f34f60bd
   
{"_id":"_design/2b836b080d41d5929e6cf097a1364826f34f60bd","_rev":"1-583b3550340ed86a26f2c7b83b1f9625","language":"query","views":{"a-index":{"map":{"fields":{"a":"asc"},"partial_filter_selector":{}},"reduce":"_count","options":{"def":{"fields":["a"]}}}}}
   
   # Now we POST to explain:
   curl -X POST -H "Content-Type: application/json" localhost:15984/db/_explain 
-d '{
     "selector": {
       "a": {
         "$gte": "1970-01-01",
         "$lt": "1970-01-31"
       },
       "b": 1
     }
   }' | jq .
   {
     "dbname": "db",
     "index": {
       "ddoc": "_design/2b836b080d41d5929e6cf097a1364826f34f60bd",
       "name": "a-index",
       "type": "json",
       "def": {
         "fields": [
           {
             "a": "asc"
           }
         ]
       }
     },
     "selector": {
       "$and": [
         {
           "$and": [
             {
               "a": {
                 "$gte": "1970-01-01"
               }
             },
             {
               "a": {
                 "$lt": "1970-01-31"
               }
             }
           ]
         },
         {
           "b": {
             "$eq": 1
           }
         }
       ]
     },
     "opts": {
       "use_index": [],
       "bookmark": "nil",
       "limit": 25,
       "skip": 0,
       "sort": {},
       "fields": "all_fields",
       "r": [
         49
       ],
       "conflicts": false,
       "stale": false,
       "update": true,
       "stable": false,
       "execution_stats": false
     },
     "limit": 25,
     "skip": 0,
     "fields": "all_fields",
     "mrargs": {
       "include_docs": true,
       "view_type": "map",
       "reduce": false,
       "start_key": [
         "1970-01-01"
       ],
       "end_key": [
         "1970-01-31",
         "<MAX>"
       ],
       "direction": "fwd",
       "stable": false,
       "update": true
     }
   }
   ```
   
   The reason might be because of #1014 (you have an implicit and).
   
   You'll see this fix with the release of 2.2.0.

----------------------------------------------------------------
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

Reply via email to