Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-12231

explain() for GeoSearchCursor broken

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6.0-rc0
    • Affects Version/s: 2.4.8, 2.5.4
    • Component/s: Geo
    • Labels:
      None
    • Fully Compatible
    • ALL
    • Hide

      All these examples below require a dataset and index, which can be created with the attached gscexplain.js file.

      Show
      All these examples below require a dataset and index, which can be created with the attached gscexplain.js file.
    • 0

      I found several problems with the explain() output for GeoSearchCursors.

      Table Of Contents
      1. In versions 2.4.8 and below, the millis value of a GeoSearchCursor from a 2d index is always 0
      2. Version 2.5.4 returns different numbers than version 2.4.8 for nscanned, nscannedObjects, etc.
      3. The nscanned value does not show the actual number of scanned documents
      4. The index name is not shown for GeoSearchCursor
      1. millis always 0

      In versions 2.4.8 and below, the millis value of a GeoSearchCursor from a 2d index is always 0

      This find took 2.5 seconds, but millis returns 0

      > var t = new ISODate(); printjson(db.gscexplain.find({loc: {$near: [40, 40]}, _id: {$lt: 50}}).explain()); print(new ISODate() - t);
      {
          "cursor" : "GeoSearchCursor",
          "isMultiKey" : false,
          "n" : 50,
          "nscannedObjects" : 50,
          "nscanned" : 50,
          "nscannedObjectsAllPlans" : 50,
          "nscannedAllPlans" : 50,
          "scanAndOrder" : false,
          "indexOnly" : false,
          "nYields" : 0,
          "nChunkSkips" : 0,
          "millis" : 0,
          "indexBounds" : {
      
          },
          "server" : "enter.local:27017"
      }
      2517
      

      In version 2.5.4, the millis display seems to be fixed (however, now it takes 1 second longer, but that's another issue).

      > var t = new ISODate(); printjson(db.gscexplain.find({loc: {$near: [40, 40]}, _id: {$lt: 50}}).explain()); print(new ISODate() - t);
      {
          "cursor" : "GeoSearchCursor",
          "isMultiKey" : false,
          "n" : 50,
          "nscannedObjects" : 51,
          "nscanned" : 51,
          "nscannedObjectsAllPlans" : 51,
          "nscannedAllPlans" : 51,
          "scanAndOrder" : false,
          "indexOnly" : false,
          "nYields" : 0,
          "nChunkSkips" : 0,
          "millis" : 3545,
          "server" : "enter.local:27017"
      }
      3548
      
      2. nscanned differs in 2.5.4

      Version 2.5.4 returns different numbers than version 2.4.8 for nscanned, nscannedObjects, etc.

      See two explain examples above. The 2.4.8 version returns nscanned:50, the 2.5.4 version returns nscanned: 51.

      3. nscanned incorrect

      The nscanned value does not show the actual number of scanned documents

      The query

      db.gscexplain.find({loc: {$near: [40, 40]} }).explain()
      

      returned nscanned:100 (or nscanned:101 for 2.5.4).

      Using the command form of the same query returns very different numbers for nscanned:

      > db.runCommand({geoNear: "gscexplain", near: [40, 40] })['stats']
      {
          "btreelocs" : 0,
          "maxDistance" : 0.005736338360377385,
          "avgDistance" : 0.003546263440475973,
          "objectsLoaded" : 217,
          "nscanned" : 611,
          "time" : 3
      }
      
      4. No index name

      The index name is not shown for GeoSearchCursor

      Other indexes state the name, for example "cursor" : "BtreeCursor a_1". The GeoSearchCursor only writes "cursor" : "GeoSearchCursor". While this may be less of an issue currently, as only one geo index is allowed per collection, we should still be consistent here for when this limitation is lifted in the future.

            Assignee:
            benety.goh@mongodb.com Benety Goh
            Reporter:
            thomas.rueckstiess@mongodb.com Thomas Rueckstiess
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: