4
我有一個集合中有150萬個文檔,其索引爲「name」字段。像db.things.find({name: /^foo/i})
這樣的查詢大約需要5秒,這很慢。具有相同記錄的相似MySQL表在少於10毫秒內執行SELECT * FROM things WHERE name LIKE 'foo%'
。MongoDB中緩慢的正則表達式查詢
蒙戈的解釋:
db.things.find({name: /^foo/i}).limit(10).explain()
{
"cursor" : "BtreeCursor name_1 multi",
"nscanned" : 325730,
"nscannedObjects" : 10,
"n" : 10,
"millis" : 4758,
"nYields" : 89,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
"name" : [
[
"",
{
}
],
[
/^foo/i,
/^foo/i
]
]
}
}
所以是正則表達式查詢是緩慢蒙戈還是我做錯了?