Why are there so many scanned objects?

I have a table with the following objects:

> db.shapes.find()
{ "_id" : "P1", "amenity" : "restaurant", "shape" : { "type" : "Point", 
"coordinates" : [ 2, 2 ] } }
{ "_id" : "P2", "amenity" : "restaurant", "shape" : { "type" : "Point", 
"coordinates" : [ 2, 4 ] } }
{ "_id" : "P3", "amenity" : "police", "shape" : { "type" : "Point", 
"coordinates" : [ 4, 2 ] } }
{ "_id" : "P4", "amenity" : "police", "shape" : { "type" : "Point", 
"coordinates" : [ 4, 4 ] } }

Explanation () on the following query gives a strange (in my opinion) result:

> db.shapes.find({shape:{$nearSphere:{$geometry:{type: "Point", coordinates: 
 [0,0]}}}}, {id:1, amenity:1}).limit(2).explain()
{
        "cursor" : "S2NearCursor",
        "isMultiKey" : false,
        "n" : 2,
        "nscannedObjects" : 22,
        "nscanned" : 22,
        "nscannedObjectsAllPlans" : 22,
        "nscannedAllPlans" : 22,
        "scanAndOrder" : false,
        "indexOnly" : false,
        "nYields" : 0,
        "nChunkSkips" : 0,
        "millis" : 1,
        "indexBounds" : {

        },
        "server" : "DBTest:27017",
        "filterSet" : false
}

Why are there many objects scanned? I mean, the table has only 4 objects and a mongodb 22 scan?

I am grateful for any explanation.

Bye, Andre


> db.shapes.find({shape:{$nearSphere:{$geometry:{type: "Point", coordinates:
...  [0,0]}}}}, {id:1, amenity:1}).limit(2).explain(1)
{
        "cursor" : "S2NearCursor",
        "isMultiKey" : false,
        "n" : 2,
        "nscannedObjects" : 22,
        "nscanned" : 22,
        "nscannedObjectsAllPlans" : 22,
        "nscannedAllPlans" : 22,
        "scanAndOrder" : false,
        "indexOnly" : false,
        "nYields" : 0,
        "nChunkSkips" : 0,
        "millis" : 1,
        "indexBounds" : {

        },
        "allPlans" : [
                {
                        "cursor" : "S2NearCursor",
                        "isMultiKey" : false,
                        "n" : 2,
                        "nscannedObjects" : 22,
                        "nscanned" : 22,
                        "scanAndOrder" : false,
                        "indexOnly" : false,
                        "nChunkSkips" : 0,
                        "indexBounds" : {

                        }
                }
        ],
        "server" : "DBTest:27017",
        "filterSet" : false,
        "stats" : {
                "type" : "LIMIT",
                "works" : 22,
                "yields" : 0,
                "unyields" : 0,
                "invalidates" : 0,
                "advanced" : 2,
                "needTime" : 20,
                "needFetch" : 0,
                "isEOF" : 1,
                "children" : [
                        {
                                "type" : "PROJECTION",
                                "works" : 22,
                                "yields" : 0,
                                "unyields" : 0,
                                "invalidates" : 0,
                                "advanced" : 2,
                                "needTime" : 0,
                                "needFetch" : 0,
                                "isEOF" : 0,
                                "children" : [
                                        {
                                                "type" : "GEO_NEAR_2DSPHERE",
                                                "works" : 22,
                                                "yields" : 0,
                                                "unyields" : 0,
                                                "invalidates" : 0,
                                                "advanced" : 2,
                                                "needTime" : 0,
                                                "needFetch" : 0,
                                                "isEOF" : 0,
                                                "children" : [ ]
                                        }
                                ]
                        }
                ]
        }
}
+4
source share
1 answer

It looks like you are using version 2.4 and working at https://jira.mongodb.org/browse/SERVER-12231 , which has been fixed for version 2.6. If you are updating, most likely you will no longer see fake nscanned numbers in the explain () message.

0
source

Source: https://habr.com/ru/post/1543947/


All Articles