Mongodb 2.4 2dsphere查询非常慢(使用$ geoIntersects)? [英] Mongodb 2.4 2dsphere queries very slow (using $geoIntersects)?

查看:929
本文介绍了Mongodb 2.4 2dsphere查询非常慢(使用$ geoIntersects)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mongod.log显示:

mongod.log shows:

 {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

该集合有大约10k条记录,其中 deliver_area 是多边形(GeoJSON)的字段之一,并且 2dsphere 索引

The collection has about 10k records, where deliver_area is one of the fields which is a Polygon(GeoJSON) and has a 2dsphere index

这是我的查询:

db.area_coll.find( { 
    id: 59, 
    deliver_area: { 
        $geoIntersects: { 
            $geometry: { 
                type: "Point", 
                coordinates: [ 116.3175773620605, 39.97607231140137 ] 
            } 
        } 
    } 
})

Expl结果:

{
    "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]

[116.3175773620605,39.97607231140137]

我也认为你没有复制整个日志ne,因为它只是提到区域而不是 deliver_area

I also don't think you have reproduced your whole log line, as it just mentions area and not deliver_area.

但是,它们非常慢。在第一种情况下,花了103毫秒,在某些情况下可能会发生,因为您的服务器正在执行其他IO。第二个查询需要5ms,因为 explain()输出告诉你。

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. The second query took 5ms as the explain() output tells you.

但最引人注目的是你的主要标准是 id:59 。我不知道您的 _id 字段是什么,但如果您在 id 上设置索引,那么这甚至不应该必须使用 2dsphere 索引 - 除非您当然有许多 id = 59 的文档。在这种情况下,使用 {id:1,deliver_area:'2dsphere'} 上的复合键可能会更好。

But what is most striking is that your main criterion is 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. In that case, you could be better off with a compound key on { id: 1, deliver_area: '2dsphere' }.

这篇关于Mongodb 2.4 2dsphere查询非常慢(使用$ geoIntersects)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆