【问题标题】:Mongodb 2.4 2dsphere queries very slow (using $geoIntersects)?Mongodb 2.4 2dsphere 查询非常慢(使用 $geoIntersects)?
【发布时间】:2013-08-03 10:49:48
【问题描述】:

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

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

这是我的查询:

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

解释结果:

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

【问题讨论】:

    标签: mongodb indexing geospatial


    【解决方案1】:

    日志中的查询与你运行的查询不匹配,位置不同:

    [ 116.3426399230957, 39.95959281921387 ] vs.
    [ 116.3175773620605, 39.97607231140137 ]

    我也不认为你已经复制了你的整个日志行,因为它只提到了area 而不是deliver_area

    但是,它们并不真的很慢。在第一种情况下,它花费了 103 毫秒,在某些情况下,这可能会发生在您的服务器正在执行其他 IO 时。正如explain() 输出告诉你的那样,第二个查询花费了 5 毫秒。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-01
      • 2021-04-17
      • 2016-07-02
      • 1970-01-01
      • 1970-01-01
      • 2014-12-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多