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

Covered query over compound index using the second field does not results in an index-only query

    • ALL
    • Hide

      Have a collection with this index:

      {
          "a" : 1,
          "b" : -1,
          "c" : 1
      }
      

      query this:

      { b : { $lte : 1262343601554}}, {b : 1, _id : 0}
      

      will not even use the index… so we hint the index. and limit to 10.
      An explain tells now:

      {
          "cursor" : "BtreeCursor indexName",
          "isMultiKey" : false,
          "n" : 10,
          "nscannedObjects" : 72,
          "nscanned" : 72,
          "nscannedObjectsAllPlans" : 72,
          "nscannedAllPlans" : 72,
          "scanAndOrder" : false,
          "indexOnly" : false,
      …
      
      Show
      Have a collection with this index: { "a" : 1, "b" : -1, "c" : 1 } query this: { b : { $lte : 1262343601554}}, {b : 1, _id : 0} will not even use the index… so we hint the index. and limit to 10. An explain tells now: { "cursor" : "BtreeCursor indexName" , "isMultiKey" : false , "n" : 10, "nscannedObjects" : 72, "nscanned" : 72, "nscannedObjectsAllPlans" : 72, "nscannedAllPlans" : 72, "scanAndOrder" : false , "indexOnly" : false , …

      We have a non sharded collection with a compound index.
      On a query using only the second field of the compound index and restricting the returned fields to those of the index the query will not be a covered query.

      But even as it has to go through more elements of the index it should only use the index.

            Assignee:
            Unassigned Unassigned
            Reporter:
            breitlauch Daniel Breitlauch
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: