慢MongoDB查询:你能解释一下原因吗? [英] Slow MongoDB query: can you explain why?
本文介绍了慢MongoDB查询:你能解释一下原因吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个MongoDB查询需要花费不合理的长时间才能运行,但是:
I have a MongoDB query that's taking an unreasonably long time to run, but it:
- 只扫描6个对象
- 点击索引
- 一直需要~1500毫秒(不是分页或其他方式占用)
- index miss%is mongostat中的0
- is only scanning 6 objects
- hits an index
- consistently takes ~1500ms (wasn't paging or otherwise occupied)
- index miss% is 0 in mongostat
它出现在探查器中(没有explain()),我不明白为什么它这么慢。有什么想法吗?
It showed up in the profiler (without the explain()), and I don't understand why it's so slow. Any ideas?
gimmebar:PRIMARY> db.assets.find({ owner: "123", avatar: false, private: false }).sort({date: -1}).explain()
{
"cursor" : "BtreeCursor owner_1_avatar_1_date_-1",
"nscanned" : 6,
"nscannedObjects" : 6,
"n" : 6,
"millis" : 1567,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
"owner" : [
[
"123",
"123"
]
],
"avatar" : [
[
false,
false
]
],
"date" : [
[
{
"$maxElement" : 1
},
{
"$minElement" : 1
}
]
]
}
}
推荐答案
缺少私有
键的索引?
BtreeCursor owner_1_avatar_1_date_-1
vs .find({owner:123,avatar:false,private:false})。sort({date:-1})
这篇关于慢MongoDB查询:你能解释一下原因吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文