mongodb - Slow range query on a multikey index -


i have mongodb collection named post 35 million objects. collection has 2 secondary indexes defined follows.

> db.post.getindexkeys() [     {         "_id" : 1     },     {         "namespace" : 1,         "domain" : 1,         "post_id" : 1     },     {         "namespace" : 1,         "post_time" : 1,         "tags" : 1  // array field     } ] 

i expect following query, filters namespace , post_time, run in reasonable time without scanning objects.

>db.post.find({post_time: {"$gte" : isodate("2013-04-09t00:00:00z"), "$lt" : isodate("2013-04-09t01:00:00z")}, namespace: "my_namespace"}).count() 7408 

however, takes mongodb @ least ten minutes retrieve result and, curiously, manages scan 70 million objects job according explain function.

> db.post.find({post_time: {"$gte" : isodate("2013-04-09t00:00:00z"), "$lt" : isodate("2013-04-09t01:00:00z")}, namespace: "my_namespace"}).explain() {     "cursor" : "btreecursor namespace_1_post_time_1_tags_1",     "ismultikey" : true,     "n" : 7408,     "nscannedobjects" : 69999186,     "nscanned" : 69999186,     "nscannedobjectsallplans" : 69999186,     "nscannedallplans" : 69999186,     "scanandorder" : false,     "indexonly" : false,     "nyields" : 378967,     "nchunkskips" : 0,     "millis" : 290048,     "indexbounds" : {         "namespace" : [             [                 "my_namespace",                 "my_namespace"             ]         ],         "post_time" : [             [                 isodate("2013-04-09t00:00:00z"),                 isodate("292278995-01--2147483647t07:12:56.808z")             ]         ],         "tags" : [             [                 {                     "$minelement" : 1                 },                 {                     "$maxelement" : 1                 }             ]         ]     },     "server" : "localhost:27017" } 

the difference between number of objects , number of scans must caused lengths of tag arrays (which equal 2). still, don't understand why post_time filter not make use of index.

can tell me might missing?

(i working on descent machine 24 cores , 96 gb ram. using mongodb 2.2.3.)

found answer in question: order of $lt , $gt in mongodb range query

my index multikey index (on tags) , running range query (on post_time). apparently, mongodb cannot use both sides of range filter in case, picks $gte clause, comes first. lower limit happens lowest post_time value, mongodb starts scanning objects.

unfortunately, not whole story. trying solve problem, created non-multikey indexes mongodb insisted on using bad one. made me think problem elsewhere. finally, had drop multikey index , create 1 without tags field. fine now.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -