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

indexOnly is wrong sometimes

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Trivial - P5 Trivial - P5
    • None
    • Affects Version/s: 2.4.5
    • Component/s: None
    • None
    • ALL

      The indexOnly in an explain() is set to true even if the query needs fields which aren't in the index.
      This is the example collection:

      db.test.insert([{a:1,c:1},{a:2,c:1}])
      db.test.ensureIndex({c:1})
      db.test.find({a:1,c:1},{_id:0,c:1}).explain()
      

      This is what the explain looks like:

      > db.test.find({a:1,c:1},{_id:0,c:1}).explain()
      {
              "cursor" : "BtreeCursor c_1",
              "isMultiKey" : false,
              "n" : 1,
              "nscannedObjects" : 2,
              "nscanned" : 2,
              "nscannedObjectsAllPlans" : 4,
              "nscannedAllPlans" : 4,
              "scanAndOrder" : false,
              "indexOnly" : true,
              "nYields" : 0,
              "nChunkSkips" : 0,
              "millis" : 0,
              "indexBounds" : {
                      "c" : [
                              [
                                      1,
                                      1
                              ]
              ]
              },
              "server" : "server:27017"
      }
      

      indexOnly is set to true but MongoDB has to query on field a which is not part of the index c_1 - so it has to be false.

            Assignee:
            Unassigned Unassigned
            Reporter:
            markus@teaminternet.de Markus Ostertag
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: