Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding mongo db explain

I fired a query and tried to explain it on mongo console and got

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

Most of the things are explained in http://www.mongodb.org/display/DOCS/Explain, but I cannot understand what does nscannedObjectsAllPlans, nscannedAllPlans means. Can anyone help?

Thanks

like image 583
Global Warrior Avatar asked Sep 20 '12 10:09

Global Warrior


People also ask

What is MongoDB and how it works?

MongoDB is a document-oriented database which stores data in JSON-like documents with dynamic schema. It means you can store your records without worrying about the data structure such as the number of fields or types of fields to store values. MongoDB documents are similar to JSON objects.

What is the structure of MongoDB?

MongoDB is a document-oriented NoSQL database management system (DBMS). Unlike traditional relational DBMSs, which store data in tables consisting of rows and columns, MongoDB stores data in JSON-like structures referred to as documents.

Why is MongoDB used?

MongoDB is a document database used to build highly available and scalable internet applications. With its flexible schema approach, it's popular with development teams using agile methodologies.


1 Answers

nscanned and nscannedObjects report results for the winning query plan.

nscannedAllPlans and nscannedObjectsAllPlans report results for all plans.

Doc

Number of index entries scanned. totalKeysExamined corresponds to the nscanned field returned by cursor.explain() in earlier versions of MongoDB.

For example:

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" : [             {...},             {...}         ]     }  
like image 100
Gianfranco P. Avatar answered Oct 14 '22 09:10

Gianfranco P.