MongoDB Operations Manual crud Query performance analysis

Source: Internet
Author: User

Analyze Query Performancethe Explain () cursor method allows you to observe the operations performed by the query system. This method is useful for analyzing efficient queries and determining how indexes are used for querying. This method detects the operation of the query, not the query execution time. Because this method attempts multiple query plans, it does not accurately reflect the query execution time.
evaluate the performance of a query Use the Explain () method to invoke the method of the pointer returned by find ().
Cases:
Create an index in the Type field
db.testData.ensureIndex ({' type ': 1});
Evaluates a query on the Type field.
db.testData.find ({type: ' food '}). Explain ()
The results are 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 for the Btreecursor table name query uses an index.
The query returns N=3 records.
In order to return to these five records, the query scanned the nscanned=3 record and then read the full record of the nscannedobjects=3 bar, and if there is no index, all records will be scanned.
Compare index query Performance Manually compare a query that uses multiple fields, and you can use the hint () and explain () methods together.
Example: Evaluating an index using a different field
db.testData.find ({type: ' food '}). Hint ({type:1}). Explain ();
Results:
{
"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 ();
The execution of this sentence is unsuccessful, pending resolution
The results of these returned statistics omit queries that are executed using their respective indexes.
NOTE: If the hint () explain () method is not applicable, the query optimizer will reevaluate the query and run the multi-index query before returning the query statistics.
For more detailed explain output, see explain-results.

MongoDB Operations Manual crud Query performance analysis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.