【问题标题】:Slow distinct() MongoDB query on hashed index collection field散列索引集合字段上的 distinct() MongoDB 查询慢
【发布时间】:2016-06-20 21:30:36
【问题描述】:

我有一个 5500 万行的集合,我希望能够做到 db.collection.distinct(foo),但这很慢。 在这种情况下,整个集合中只有一个“foo”值,所以我希望它很快。

我添加了一个索引 (foo: "hashed"),但它仍然是 ~30 秒,即使只有一个值

我是否必须使用非散列索引才能获得不错的速度,还是我错过了其他方面?

编辑:我还尝试了一个 b-tree 索引,我可以说它根本没有提高速度。 { "values" : [ "foo" ], "stats" : { "n" : 55316753, "nscanned" : 55316753, "nscannedObjects" : 0, "timems" : 14783, "cursor" : "BtreeCursor baz_1" }, "ok" : 1 }

【问题讨论】:

  • 你能从db.collection.find({query}).explain("executionStats")添加转储吗?

标签: mongodb performance optimization distinct


【解决方案1】:

已通过升级到 MongoDB 3.0(我之前运行的是 2.4.9)解决了这个问题。

【讨论】:

    猜你喜欢
    • 2016-07-10
    • 1970-01-01
    • 2018-11-25
    • 1970-01-01
    • 2012-08-23
    • 1970-01-01
    • 1970-01-01
    • 2019-02-10
    • 1970-01-01
    相关资源
    最近更新 更多