【问题标题】:MongoDB index use on find all without hintMongoDB 索引在 find all 上的使用没有提示
【发布时间】:2013-09-13 15:35:59
【问题描述】:

我有一个关于如何正确编写索引以避免求助于提示的问题。

示例“测试”集合架构

{
   _id: ObjectId(<whatever>),
   a: <whatever>,
   b: <whatever>,
   c: <whatever>,
   d: <whatever>,
   e: {
         f: <whatever>,
         g: <whatever>
      }
}

“测试”索引

db.test.ensureIndex( { "a": NumberInt(1), "c": NumberInt(1), "_id": NumberInt(1), "d": NumberInt(1) }, 
                     { name: "a_1_c_1__id_1_d_1", background: true } );

不带提示的查询和带提示的查询...

> db.test.find({},{d:1}).explain();
{
    "cursor" : "BasicCursor",
    "isMultiKey" : false,
    "n" : 752,
    "nscannedObjects" : 752,
    "nscanned" : 752,
    "nscannedObjectsAllPlans" : 752,
    "nscannedAllPlans" : 752,
    "scanAndOrder" : false,
    "indexOnly" : false,
    "nYields" : 4,
    "nChunkSkips" : 0,
    "millis" : 5,
    "indexBounds" : {

    },
    "server" : <whatever>
}

> db.test.find({},{d:1}).hint("a_1_c_1__id_1_d_1").explain();
{
    "cursor" : "BtreeCursor a_1_c_1__id_1_d_1",
    "isMultiKey" : false,
    "n" : 752,
    "nscannedObjects" : 752,
    "nscanned" : 752,
    "nscannedObjectsAllPlans" : 752,
    "nscannedAllPlans" : 752,
    "scanAndOrder" : false,
    "indexOnly" : true,
    "nYields" : 0,
    "nChunkSkips" : 0,
    "millis" : 0,
    "indexBounds" : {
        "a" : [
            [
                {
                    "$minElement" : 1
                },
                {
                    "$maxElement" : 1
                }
            ]
        ],
        "c" : [
            [
                {
                    "$minElement" : 1
                },
                {
                    "$maxElement" : 1
                }
            ]
        ],
        "_id" : [
            [
                {
                    "$minElement" : 1
                },
                {
                    "$maxElement" : 1
                }
            ]
        ],
        "d" : [
            [
                {
                    "$minElement" : 1
                },
                {
                    "$maxElement" : 1
                }
            ]
        ]
    },
    "server" : <whatever>
}

我(显然)希望查询使用覆盖索引,但我不知道如何在不使用提示的情况下到达那里。是否可以?我更喜欢操纵索引而不是更改查询,但如果需要,更改查询是一种选择。

【问题讨论】:

  • 如果我将索引和查询简化为: db.test.ensureIndex( { "d": NumberInt(1) },{ name: "d_1", background: true } ); db.test.find({},{_id:0,d:1}).explain();我得到相同的 BasicCursor 结果。
  • 我相信这可以通过 JIRA 解决,atm 我认为如果您不输入查询,MongoDB 会忽略,我认为这可能会改变

标签: mongodb indexing find query-hints


【解决方案1】:

原来这是一个已知问题。为帖子道歉。

https://jira.mongodb.org/browse/SERVER-2109

【讨论】:

  • 为以后的访问者打勾并标记它,我学到了一些东西,我不知道JIRA存在,现在下次出现我可以指导他们
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-21
  • 1970-01-01
  • 2014-08-22
  • 2016-07-11
  • 1970-01-01
  • 2012-08-23
相关资源
最近更新 更多