我的數據集由包含具有整數數組的字段的文檔組成。當我計算其字段包含某些範圍內的元素的對象時,似乎索引掃描性能會隨着indexBounds值更高而降低(但該範圍掃描的值相同)。搜索更高值時索引掃描性能下降
測試數據:
for (var i = 0; i < 100000; i++) db.foo.insert({tts:(function(){var val = [];for(var j = 0; j < 100; j++) {val[j] = j} return val;})()});
db.foo.ensureIndex({tts:1});
查詢:當請求的範圍內有最高的界限
> db.foo.find({tts:{$elemMatch:{$gte:10, $lte:10}}}).explain()
{
"cursor" : "BtreeCursor tts_1",
"isMultiKey" : true,
"n" : 100000,
"nscannedObjects" : 100000,
"nscanned" : 100000,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 1,
"nChunkSkips" : 0,
"millis" : 313,
"indexBounds" : {
"tts" : [
[
10,
10
]
]
},
"server" : "localhost:27017"
}
> db.foo.find({tts:{$elemMatch:{$gte:90, $lte:90}}}).explain()
{
"cursor" : "BtreeCursor tts_1",
"isMultiKey" : true,
"n" : 100000,
"nscannedObjects" : 100000,
"nscanned" : 100000,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 1,
"nChunkSkips" : 0,
"millis" : 1286,
"indexBounds" : {
"tts" : [
[
90,
90
]
]
},
"server" : "localhost:27017"
}
其實我有近200個值在這個領域和查詢起牀慢10倍。 (在字段中的每個值屬於獨特的範圍內,所有的範圍選擇對象(100000相同量),查詢僅針對此子範圍進行範圍)
收集統計:
> db.foo.stats()
{
"ns" : "test.foo",
"count" : 100000,
"size" : 122400128,
"avgObjSize" : 1224.00128,
"storageSize" : 140763136,
"numExtents" : 12,
"nindexes" : 2,
"lastExtentSize" : 40071168,
"paddingFactor" : 1,
"systemFlags" : 1,
"userFlags" : 0,
"totalIndexSize" : 254845920,
"indexSizes" : {
"_id_" : 3262224,
"tts_1" : 251583696
},
"ok" : 1
}
是否有解決這個問題的方法?
謝謝。
您使用的是什麼版本的MongoDB? – Stennie 2012-07-11 05:50:00
2.1.2/2.1.3-pre- – 2012-07-11 07:23:30