indexing - Why MongoDB doesn't use Index Intersection? -


i trying reproduce first example of index intersection instruction (http://docs.mongodb.org/manual/core/index-intersection/) facing problem: mongo doesn't uses both indexes

my steps:

  1. download mongo (3.0.3) , install it
  2. run mongod: mongod.exe --dbpath d:\data (folder empty)
  3. run mongo: mongo.exe
  4. add indexes:

    db.orders.ensureindex({ qty: 1 }) db.orders.ensureindex({ item: 1 }) db.orders.getindexes() [{         "v" : 1,         "key" : {                 "_id" : 1         },         "name" : "_id_",         "ns" : "test.orders" }, {         "v" : 1,         "key" : {                 "qty" : 1         },         "name" : "qty_1",         "ns" : "test.orders" }, {         "v" : 1,         "key" : {                 "item" : 1         },         "name" : "item_1",         "ns" : "test.orders" }] 
  5. check query explain:

    db.orders.find( { item: "abc123", qty: { $gt: 15 } } ).explain() {     "queryplanner" : {             "plannerversion" : 1,             "namespace" : "test.orders",             "indexfilterset" : false,             "parsedquery" : {                     "$and" : [                             {                                     "item" : {                                             "$eq" : "abc123"                                     }                             },                             {                                     "qty" : {                                             "$gt" : 15                                     }                             }                     ]             },             "winningplan" : {                     "stage" : "keep_mutations",                     "inputstage" : {                             "stage" : "fetch",                             "filter" : {                                     "qty" : {                                             "$gt" : 15                                     }                             },                             "inputstage" : {                                     "stage" : "ixscan",                                     "keypattern" : {                                             "item" : 1                                     },                                     "indexname" : "item_1",                                     "ismultikey" : false,                                     "direction" : "forward",                                     "indexbounds" : {                                             "item" : [                                                     "[\"abc123\", \"abc123\"]"                                             ]                                     }                             }                     }             },             "rejectedplans" : [                     {                             "stage" : "keep_mutations",                             "inputstage" : {                                     "stage" : "fetch",                                     "filter" : {                                             "item" : {                                                     "$eq" : "abc123"                                             }                                     },                                     "inputstage" : {                                             "stage" : "ixscan",                                             "keypattern" : {                                                     "qty" : 1                                             },                                             "indexname" : "qty_1",                                             "ismultikey" : false,                                             "direction" : "forward",                                             "indexbounds" : {                                                     "qty" : [                                                             "(15.0, 1.#inf]"                                                     ]                                             }                                     }                             }                     }             ]     },     "serverinfo" : {             "host" : "localhost",             "port" : 27017,             "version" : "3.0.3",             "gitversion" : "b40106b36eecd1b4407eb1ad1af6bc60593c6105"     },     "ok" : 1 } 

as can see winningplan contains item_1 index. there rejectedplans contains qty_1 index. there no plans contains index intersection. know there lot of conditions select specific index. in case mongo doesn't plans it!

could me?

there details index selection in server-3071 jira issue cannot if still relevant 3.0. anyway:

mongodb 3.0.2 seems not consider index interaction range query. point intervals:

> db.orders.find( { item: {$eq : "abc123"}, qty: { $eq: 15 } } ).explain() ...          {             "stage" : "fetch",             "inputstage" : {                 "stage" : "keep_mutations",                 "inputstage" : {                     "stage" : "and_sorted",                     "inputstages" : [                         {                             "stage" : "ixscan",                             "keypattern" : {                                 "qty" : 1                             },                             "indexname" : "qty_1",                             "ismultikey" : false,                             "direction" : "forward",                             "indexbounds" : {                                 "qty" : [                                     "[15.0, 15.0]"                                 ]                             }                         },                         {                             "stage" : "ixscan",                             "keypattern" : {                                 "item" : 1                             },                             "indexname" : "item_1",                             "ismultikey" : false,                             "direction" : "forward",                             "indexbounds" : {                                 "item" : [                                     "[\"abc123\", \"abc123\"]"                                 ]                             }                         }                     ]                 } 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -