The explain () cursor Method for Analyzing query performance allows you to observe the operations performed by the query system. This method is very useful for analyzing efficient queries and deciding how to use indexes for queries. This method detects the query operation, rather than the query execution time. Because this method attempts multiple query plans, it cannot accurately reflect the query execution time.
The explain () cursor Method for Analyzing query performance allows you to observe the operations performed by the query system. This method is very useful for analyzing efficient queries and deciding how to use indexes for queries. This method detects the query operation, rather than the query execution time. Because this method attempts multiple query plans, it cannot accurately reflect the query execution time.
The explain () cursor Method for Analyzing query performance allows you to observe the operations performed by the query system. This method is very useful for analyzing efficient queries and deciding how to use indexes for queries. This method detects the query operation, rather than the query execution time. Because this method attempts multiple query plans, it cannot accurately reflect the query execution time.
To evaluate the performance of a query, use the explain () method to call the pointer returned by find.
Example:
Create an index in the type field
Db. testData. ensureIndex ({'type': 1 });
Evaluate a query in the type field.
Db. testData. find ({type: 'food'}). explain ()
The result is as follows:
{
"Cursor": "BtreeCursor type_1 ",
"IsMultiKey": false,
"N": 3,
"NscannedObjects": 3,
"Nscanned": 3,
"NscannedObjectsAllPlans": 3,
"NscannedAllPlans": 3,
"ScanAndOrder": false,
"IndexOnly": false,
"NYields": 1,
"NChunkSkips": 0,
"Millis": 64,
"IndexBounds ":{
"Type ":[
[
"Food ",
"Food"
]
]
},
"Server": "TT: 27017 ",
"FilterSet": false
}
The cursor value is BtreeCursor. The table name query uses an index.
N = 3 records are returned for query.
In order to return these five records, the query scans the nscanned = 3 Records, and then reads the nscannedObjects = 3 complete records. If no index is found, all records are scanned.
Compare index query performance: manually compare a query that uses multiple fields. You can use the hint () and explain () methods in combination.
For example, the index of different fields is evaluated.
Db. testData. find ({type: 'food'}). hint ({type: 1}). explain ();
Result:
{
"Cursor": "BtreeCursor type_1 ",
"IsMultiKey": false,
"N": 3,
"NscannedObjects": 3,
"Nscanned": 3,
"NscannedObjectsAllPlans": 3,
"NscannedAllPlans": 3,
"ScanAndOrder": false,
"IndexOnly": false,
"NYields": 0,
"NChunkSkips": 0,
"Millis": 40,
"IndexBounds ":{
"Type ":[
[
"Food ",
"Food"
]
]
},
"Server": "TT: 27017 ",
"FilterSet": false
}
Db. testData. find ({type: 'food'}). hint ({type: 1, name: 1}). explain ();
// This statement is not executed successfully and will be resolved
The returned statistical results ignore the queries executed using their respective indexes.
Note: If the explain () method is not applicable to hint (), the query optimizer re-evaluates the query and runs the multi-index query before returning the query statistics.
For more detailed explain output, see explain-results.