How to read Verbose Output from MongoDB-explain (1)

I have the following query.explain (1) -Output. This is a detailed conclusion, and my question is how to read it. How is the order of operations? Does it start with GEO_NEAR_2DSPHERE or with LIMIT? What promotes the field?

And most importantly, where is this documented? Could not find this in mongoDB manual :(

Query:

db.nodesWays.find( { geo:{ $nearSphere:{ $geometry:{ type: "Point", coordinates: [lon, lat] } } }, "amenity":"restaurant" }, {name:1} ).limit(10).explain(1) 

Exit:

 { "cursor" : "S2NearCursor", "isMultiKey" : false, "n" : 10, "nscannedObjects" : 69582, "nscanned" : 69582, "nscannedObjectsAllPlans" : 69582, "nscannedAllPlans" : 69582, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 543, "nChunkSkips" : 0, "millis" : 606, "indexBounds" : { }, "allPlans" : [ { "cursor" : "S2NearCursor", "isMultiKey" : false, "n" : 10, "nscannedObjects" : 69582, "nscanned" : 69582, "scanAndOrder" : false, "indexOnly" : false, "nChunkSkips" : 0, "indexBounds" : { } } ], "server" : "DBTest:27017", "filterSet" : false, "stats" : { "type" : "LIMIT", "works" : 69582, "yields" : 543, "unyields" : 543, "invalidates" : 0, "advanced" : 10, "needTime" : 69572, "needFetch" : 0, "isEOF" : 1, "children" : [ { "type" : "PROJECTION", "works" : 69582, "yields" : 543, "unyields" : 543, "invalidates" : 0, "advanced" : 10, "needTime" : 0, "needFetch" : 0, "isEOF" : 0, "children" : [ { "type" : "FETCH", "works" : 69582, "yields" : 543, "unyields" : 543, "invalidates" : 0, "advanced" : 10, "needTime" : 69572, "needFetch" : 0, "isEOF" : 0, "alreadyHasObj" : 4028, "forcedFetches" : 0, "matchTested" : 10, "children" : [ { "type" : "GEO_NEAR_2DSPHERE", "works" : 69582, "yields" : 0, "unyields" : 0, "invalidates" : 0, "advanced" : 4028, "needTime" : 0, "needFetch" : 0, "isEOF" : 0, "children" : [ ] } ] } ] } ] } } 
0
performance find mongodb sql-execution-plan
source share
1 answer

Having looked at the stats array, the sequence should be

  • GEO_NEAR_2DSPHERE β†’ scans objects of index 69582.
  • Fetch and limit β†’ Selects consistent documents with a limited number of documents.
  • Projection -> Project to return only the required fields.

The reason MongoDB wraps all actions in a LIMIT is because it aligns with the query syntax for easier interpretation.

The query uses an unknown index of type S2NearCursor . In addition to the index, he also retrieved the entire document to further reduce usability. You might also want to study indexing.

By the way, this is a known bug in MongoDB. It skips the index name when using the S2NearCursor index.

As for the detailed documentation, I myself find a little too, but you can view several online blogs.

explain.explain () - Understanding Mongo query behavior

Query Acceleration: Query Overview

I especially want to recommend that you pay attention to the last paragraph of the two blog posts. Configure, generate a query plan and try to explain the plan yourself . After doing this a few rounds, you will understand how it works.

Happy explanation. :)

0
source share

All Articles