gpt4 book ai didi

mongodb - 为什么要扫描这么多对象?

转载 作者:可可西里 更新时间:2023-11-01 09:17:08 25 4
gpt4 key购买 nike

我有一个包含以下对象的表:

> db.shapes.find()
{ "_id" : "P1", "amenity" : "restaurant", "shape" : { "type" : "Point",
"coordinates" : [ 2, 2 ] } }
{ "_id" : "P2", "amenity" : "restaurant", "shape" : { "type" : "Point",
"coordinates" : [ 2, 4 ] } }
{ "_id" : "P3", "amenity" : "police", "shape" : { "type" : "Point",
"coordinates" : [ 4, 2 ] } }
{ "_id" : "P4", "amenity" : "police", "shape" : { "type" : "Point",
"coordinates" : [ 4, 4 ] } }

以下查询的 explain() 给出了一个奇怪的(在我看来)结果:

> db.shapes.find({shape:{$nearSphere:{$geometry:{type: "Point", coordinates: 
[0,0]}}}}, {id:1, amenity:1}).limit(2).explain()
{
"cursor" : "S2NearCursor",
"isMultiKey" : false,
"n" : 2,
"nscannedObjects" : 22,
"nscanned" : 22,
"nscannedObjectsAllPlans" : 22,
"nscannedAllPlans" : 22,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 1,
"indexBounds" : {

},
"server" : "DBTest:27017",
"filterSet" : false
}

为什么要扫描这么多对象?我的意思是, table 只有 4对象和 mongodb 扫描 22 ?

感谢任何解释。

再见,安德烈


> db.shapes.find({shape:{$nearSphere:{$geometry:{type: "Point", coordinates:
... [0,0]}}}}, {id:1, amenity:1}).limit(2).explain(1)
{
"cursor" : "S2NearCursor",
"isMultiKey" : false,
"n" : 2,
"nscannedObjects" : 22,
"nscanned" : 22,
"nscannedObjectsAllPlans" : 22,
"nscannedAllPlans" : 22,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 1,
"indexBounds" : {

},
"allPlans" : [
{
"cursor" : "S2NearCursor",
"isMultiKey" : false,
"n" : 2,
"nscannedObjects" : 22,
"nscanned" : 22,
"scanAndOrder" : false,
"indexOnly" : false,
"nChunkSkips" : 0,
"indexBounds" : {

}
}
],
"server" : "DBTest:27017",
"filterSet" : false,
"stats" : {
"type" : "LIMIT",
"works" : 22,
"yields" : 0,
"unyields" : 0,
"invalidates" : 0,
"advanced" : 2,
"needTime" : 20,
"needFetch" : 0,
"isEOF" : 1,
"children" : [
{
"type" : "PROJECTION",
"works" : 22,
"yields" : 0,
"unyields" : 0,
"invalidates" : 0,
"advanced" : 2,
"needTime" : 0,
"needFetch" : 0,
"isEOF" : 0,
"children" : [
{
"type" : "GEO_NEAR_2DSPHERE",
"works" : 22,
"yields" : 0,
"unyields" : 0,
"invalidates" : 0,
"advanced" : 2,
"needTime" : 0,
"needFetch" : 0,
"isEOF" : 0,
"children" : [ ]
}
]
}
]
}
}

最佳答案

看起来您使用的是 2.4 版并遇到了 https://jira.mongodb.org/browse/SERVER-12231已在 2.6 版中修复。如果升级,您可能不会再在 explain() 输出中看到伪造的 nscanned 数字。

关于mongodb - 为什么要扫描这么多对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24134683/

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