gpt4 book ai didi

mongodb - Mongo 突然忽略大型集合中的索引

转载 作者:可可西里 更新时间:2023-11-01 09:15:14 26 4
gpt4 key购买 nike

我有一个包含大约 2200 万个文档的集合,每个文档都非常小。这个集合每天增长数千条记录,所以 according to this documentation我们的查询计划一直都是无效的,并且可以毫无问题地重建。一周前,我向该集合添加了一个新索引(在后台)并对其执行了一些查询。大约一天后,我们经历了停机时间,并将其追溯到突然进行全面扫描的例行查询(可能每秒针对该集合运行一次)。我捕获了一些分析数据来显示这一点。为了解决这个问题,我重新启动了 mongo,它又运行了大约一天才再次出现。凭直觉,我删除了我创建的新索引,此后我们再也没有看到这个问题。mongo在什么情况下突然开始忽略索引?提供索引提示可能会解决这个问题,但这会让我觉得我为任何集合编写的所有 mongo 查询都应该提供索引提示。真的有必要吗?

编辑:我可以提供有问题的查询:
Following.find( {user: userDoc._id, followedUser: {$exists: true}} )
以及捕获的配置文件数据:

{
"op" : "query",
"ns" : "figure1.following",
"query" : {
"$query" : {
"followedUser" : {
"$exists" : true
},
"user" : ObjectId("54243fce5fce0dcc0d2e23b3")
},
"orderby" : {
"created" : -1
}
},
"ntoreturn" : 0,
"ntoskip" : 0,
"nscanned" : 22542697,
"nscannedObjects" : 22542697,
"keyUpdates" : 0,
"numYield" : 8645,
"lockStats" : {
"timeLockedMicros" : {
"r" : NumberLong(720504269),
"w" : NumberLong(0)
},
"timeAcquiringMicros" : {
"r" : NumberLong(26364170),
"w" : NumberLong(2108)
}
},
"nreturned" : 2,
"responseLength" : 82,
"millis" : 390517,
"execStats" : {
"type" : "PROJECTION",
"works" : 22542699,
"yields" : 178440,
"unyields" : 178440,
"invalidates" : 0,
"advanced" : 2,
"needTime" : 0,
"needFetch" : 0,
"isEOF" : 1,
"children" : [
{
"type" : "FETCH",
"works" : 22542699,
"yields" : 178440,
"unyields" : 178440,
"invalidates" : 0,
"advanced" : 2,
"needTime" : 22542696,
"needFetch" : 0,
"isEOF" : 1,
"alreadyHasObj" : 0,
"forcedFetches" : 0,
"matchTested" : 2,
"children" : [
{
"type" : "IXSCAN",
"works" : 22542698,
"yields" : 178440,
"unyields" : 178440,
"invalidates" : 0,
"advanced" : 22542697,
"needTime" : 1,
"needFetch" : 0,
"isEOF" : 1,
"keyPattern" : "{ created: 1.0 }",
"isMultiKey" : 0,
"boundsVerbose" : "field #0['created']: [MaxKey, MinKey]",
"yieldMovedCursor" : 0,
"dupsTested" : 0,
"dupsDropped" : 0,
"seenInvalidated" : 0,
"matchTested" : 0,
"keysExamined" : 22542697,
"children" : [ ]
}
]
}
]
},
"ts" : ISODate("2015-02-06T21:09:43.550Z"),
"client" : "10.165.78.55",
"allUsers" : [ ],
"user" : ""
}

followedUseruser 都单独索引,一起索引,并与created 字段一起索引。在我在 created 字段(您可以在配置文件数据中看到它作为排序字段)上添加索引后大约一天,问题开始了。我意识到 $exists 不会使用索引,这是我可以改变的,但我担心的是 mongo 似乎选择了一个非常糟糕的查询计划。

附加说明:问题首先发生在 mongo 2.6.4 中,我可以看到它有一个看起来与此非常相似的问题 (JIRA-14961)。但是在我杀掉mongo并重启后,它运行的是2.6.6,问题又出现了,所以我认为这不是bug 14961中的问题。

最佳答案

我自己也遇到过这个确切的问题,我怀疑这可能是原因:

https://jira.mongodb.org/browse/SERVER-15802

从 2.6.3 升级到 2.6.9 后,我还没有看到它再次出现(到目前为止)。

关于mongodb - Mongo 突然忽略大型集合中的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28438410/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com