28

我发出了一个查询并试图在 mongo 控制台上解释它并得到

"isMultiKey" : true,
"n" : 8,
"nscannedObjects" : 17272,
"nscanned" : 17272,
"nscannedObjectsAllPlans" : 21836,
"nscannedAllPlans" : 21836,
"scanAndOrder" : true,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 184,

大多数事情都在http://www.mongodb.org/display/DOCS/Explain中进行了解释,但我不明白 nscannedObjectsAllPlans, nscannedAllPlans 是什么意思。任何人都可以帮忙吗?

谢谢

4

1 回答 1

24

nscannednscannedObjects报告获胜查询计划的结果。

nscannedAllPlansnscannedObjectsAllPlans报告所有计划的结果。

文档

扫描的索引条目数。totalKeysExamined对应于MongoDB 早期版本中nscanned返回的字段。cursor.explain()

例如:

t = db.jstests_explainb;
t.drop();

t.ensureIndex( { a:1, b:1 } );
t.ensureIndex( { b:1, a:1 } );

t.save( { a:0, b:1 } );
t.save( { a:1, b:0 } );

// Older mongodb (< 3.0? )
t.find( { a:{ $gte:0 }, b:{ $gte:0 } } ).explain( true );
    {
      "isMultiKey": false,
      "n": 2,
      "nscannedObjects": 2,
      "nscanned": 2,
      "nscannedObjectsAllPlans": 6,
      "nscannedAllPlans": 6,
      "scanAndOrder": false,
      "indexOnly": false,
      "nYields": 0,
      "nChunkSkips": 0,
      "millis": 2,
    ...
    }

// MongoDB 4.4
t.find( { a:{ $gte:0 }, b:{ $gte:0 } } ).explain( true );
{
    "queryPlanner" : {
        "plannerVersion" : 1,
        "namespace" : "test.jstests_explainb",
        ...
        "queryHash" : "CB67518C",
        "planCacheKey" : "5E76CDD1",
        "winningPlan" : {
            "stage" : "FETCH",
            "inputStage" : {
                "stage" : "IXSCAN",
                "keyPattern" : {
                    "a" : 1,
                    "b" : 1
                },
                "indexName" : "a_1_b_1",
            }
        },
        "rejectedPlans" : [
            {
                "stage" : "FETCH",
                "inputStage" : {
                    "stage" : "IXSCAN",
                    "keyPattern" : {
                        "b" : 1,
                        "a" : 1
                    },
                    "indexName" : "b_1_a_1",
                }
            }
        ],
        ...
    },
    "executionStats" : {
        "executionSuccess" : true,
        "nReturned" : 2,
        "executionTimeMillis" : 0,
        "totalKeysExamined" : 2, // <-- same as `nscanned`
        "totalDocsExamined" : 2, // <--
        "executionStages" : { ... }
        "allPlansExecution" : [
            {...},
            {...}
        ]
    }

于 2012-09-20T12:48:53.567 回答