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

incorrect use of sparse index to sort query results

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.5.5
    • Affects Version/s: 2.2.2
    • Component/s: Querying
    • Labels:
    • Major Change
    • ALL

      In some cases, sorting a query results in the use of a sparse index, which in turn results in a lesser number of documents being returned than would normally be returned by the query. This strikes me as incorrect.

      Example:

      Suppose I have a collection "foo" that contains 1000 documents. 750 of those documents include a value for the field "bar", while the other 250 do not. Suppose I have a sparse index "bar_1" on the field "bar". The index will contain the 750 documents that have a value for the field.

      The following query results in 1000 documents:
      db.foo.find()

      The following query results in only 750 documents, despite the identical query parameters:
      db.foo.find().sort(

      { bar: 1 }

      )

      I understand why this behaves the way it does, but in my opinion the behavior is incorrect.

            Assignee:
            benety.goh@mongodb.com Benety Goh
            Reporter:
            mhurne Matt Hurne
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: