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

Whole index scan on sparse index should be able to provide a sort

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.1
    • Component/s: Querying
    • None
    • Query Optimization

      Sparse indexes can generally be used to answer queries that include a "non-sparse" predicate on an indexed field.

      This is not the case, however, for query plans that perform a whole index scan to provide a sort. These query plans should be able to use sparse indexes if a "non-sparse" predicate is given on an indexed field.

      > db.foo.dropIndexes()
      {
      	"nIndexesWas" : 2,
      	"msg" : "non-_id indexes dropped for collection",
      	"ok" : 1
      }
      > db.foo.ensureIndex({a:1,b:1},{sparse:true})
      {
      	"createdCollectionAutomatically" : true,
      	"numIndexesBefore" : 1,
      	"numIndexesAfter" : 2,
      	"ok" : 1
      }
      > db.foo.find({a:1,b:1}).sort({a:1}).explain().cursor
      BtreeCursor a_1_b_1 // Bounded index scan; sparse index is used.
      > db.foo.find({b:1}).sort({a:1}).explain().cursor
      BasicCursor // Whole index scan; sparse index not used.
      

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            rassi J Rassi
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: