[英]Mongodb 2.4 2dsphere queries very slow (using $geoIntersects)?
mongod.log shows: mongod.log显示:
{deliver_area: { $geoIntersects:
{ $geometry: {
type: "Point",
coordinates: [ 116.3426399230957, 39.95959281921387 ]
} }
} }
ntoreturn:0
ntoskip:0
nscanned:2965
keyUpdates:0
numYields: 2 locks(micros)
r:136723
nreturned:52
reslen:23453
103ms
The collection has about 10k records, where deliver_area
is one of the fields which is a Polygon(GeoJSON) and has a 2dsphere
index 该集合大约有1万条记录,其中
deliver_area
是字段之一,是Polygon(GeoJSON)并具有2dsphere
索引
This is my query: 这是我的查询:
db.area_coll.find( {
id: 59,
deliver_area: {
$geoIntersects: {
$geometry: {
type: "Point",
coordinates: [ 116.3175773620605, 39.97607231140137 ]
}
}
}
})
Explain result: 说明结果:
{
"cursor" : "S2Cursor",
"isMultiKey" : true,
"n" : 0,
"nscannedObjects" : 0,
"nscanned" : 3887,
"nscannedObjectsAllPlans" : 0,
"nscannedAllPlans" : 3887,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 5,
"indexBounds" : {
},
"nscanned" : 3887,
"matchTested" : NumberLong(666),
"geoTested" : NumberLong(0),
"cellsInCover" : NumberLong(1),
"server" : "testing:27017"
}
The query in the log does not match the query that you run as, the location is different: 日志中的查询与您所运行的查询不匹配,位置不同:
[ 116.3426399230957, 39.95959281921387 ]
vs. [ 116.3426399230957, 39.95959281921387 ]
与
[ 116.3175773620605, 39.97607231140137 ]
I also don't think you have reproduced your whole log line, as it just mentions area
and not deliver_area
. 我也不认为您已复制了整个日志行,因为它只提到
area
而不是deliver_area
。
However, they are not really slow . 但是,它们并不是真的很慢 。 In the first case, it took 103ms, which in some cases might happen as your server is doing other IO.
在第一种情况下,它花费了103毫秒,在某些情况下,这可能是因为服务器正在执行其他IO。 The second query took 5ms as the
explain()
output tells you. 第二个查询用了5毫秒,因为
explain()
输出告诉您。
But what is most striking is that your main criterion is id: 59
. 但最引人注目的是您的主要标准是
id: 59
。 I don't know what your _id
field is, but if you set an index on id
then this should not even have to use a 2dsphere
index at all — unless you have of course many documents where id=59
. 我不知道您的
_id
字段是什么,但是如果您在id
上设置索引,那么它甚至根本不需要使用2dsphere
索引-除非您当然有许多id=59
文档。 In that case, you could be better off with a compound key on { id: 1, deliver_area: '2dsphere' }
. 在这种情况下,最好在
{ id: 1, deliver_area: '2dsphere' }
上使用复合键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.