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

Sort provided from index does not respect query collation

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.3.9
    • Component/s: Querying
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Sprint:
      Query 16 (06/24/16)

      Description

      When we use an index to provide a sort, but the filter does not require that the index respect the query's collation, we fail to check that the index respects the query's collation.

      Without an index, we respect the collation (strength: 2 indicates case-insensitivity):

      > db.coll.find({}, {_id: 0}).sort({a: 1}).collation({locale: "en_US", strength: 2})
      { "a" : "a" }
      { "a" : "A" }
      { "a" : "b" }
      { "a" : "B" }
      

      With an index, we do not respect the collation:

      > db.coll.ensureIndex({a: 1})
      > db.coll.find({}, {_id: 0}).sort({a: 1}).collation({locale: "en_US", strength: 2})
      { "a" : "A" }
      { "a" : "B" }
      { "a" : "a" }
      { "a" : "b" }
      

      An example where the filter doesn't require the index respect the query's collation:

      > db.coll.find({a: {$exists: true}}, {_id: 0}).sort({a: 1}).collation({locale: "en_US", strength: 2});
      { "a" : "a" }
      { "a" : "A" }
      { "a" : "b" }
      { "a" : "B" }
       
      > db.coll.ensureIndex({a:1})
      > db.coll.find({a: {$exists: true}}, {_id: 0}).sort({a: 1}).collation({locale:"en_US",strength:2})
      { "a" : "A" }
      { "a" : "B" }
      { "a" : "a" }
      { "a" : "b" }
      

      Another example where the filter doesn't require the index respect the query's collation:

      > db.coll.find({a: {$gt: {b: 5}}}, {_id: 0}).sort({a: 1}).collation({locale:"en_US", strength: 2})
      { "a" : { "b" : "A" } }
      { "a" : { "b" : "a" } }
      { "a" : { "b" : "B" } }
      { "a" : { "b" : "b" } }
       
      > db.coll.ensureIndex({a: 1})
      > db.coll.find({a: {$gt: {b: 5}}}, {_id: 0}).sort({a: 1}).collation({locale: "en_US", strength: 2})
      { "a" : { "b" : "A" } }
      { "a" : { "b" : "B" } }
      { "a" : { "b" : "a" } }
      { "a" : { "b" : "b" } }
      

        Attachments

          Activity

            People

            Assignee:
            david.hatch David Hatch
            Reporter:
            tess.avitabile Tess Avitabile
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: