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

Retrieving fields from a covered index doesn't use the covered index when fields are specified with _true_ instead of _1_

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.0.1
    • Component/s: Querying
    • None
    • ALL

      When only retrieving fields from a covered index, if the fields to be returned are specified with true instead of 1, explain() indicates that the covered index isn't used.

      PRIMARY> db.version();
      2.0.1
      PRIMARY> db.temp.getIndexes();
      [
              {
                      "v" : 1,
                      "key" : {
                              "_id" : 1
                      },
                      "ns" : "test.temp",
                      "name" : "_id_"
              }
      ]
      PRIMARY> db.temp.find({_id:'1'},{_id:true}).explain();
      {
              "cursor" : "BtreeCursor _id_",
              "nscanned" : 0,
              "nscannedObjects" : 0,
              "n" : 0,
              "millis" : 13,
              "nYields" : 0,
              "nChunkSkips" : 0,
              "isMultiKey" : false,
              "indexOnly" : false,
              "indexBounds" : {
                      "_id" : [
                              [
                                      "1",
                                      "1"
                              ]
                      ]
              }
      }
      PRIMARY> db.temp.find({_id:'1'},{_id:1}).explain();
      {
              "cursor" : "BtreeCursor _id_",
              "nscanned" : 0,
              "nscannedObjects" : 0,
              "n" : 0,
              "millis" : 0,
              "nYields" : 0,
              "nChunkSkips" : 0,
              "isMultiKey" : false,
              "indexOnly" : true,
              "indexBounds" : {
                      "_id" : [
                              [
                                      "1",
                                      "1"
                              ]
                      ]
              }
      }
      

      If explain is truly correct here, this seems to violate the principle of least astonishment.

            Assignee:
            Unassigned Unassigned
            Reporter:
            mkwan Mark Kwan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: