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

Sort provided from index does not respect query collation

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 3.3.9
    • None
    • Querying
    • None
    • Fully Compatible
    • ALL
    • 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

            david.hatch David Hatch
            tess.avitabile@mongodb.com Tess Avitabile (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: