Sort provided from index does not respect query collation

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • 3.3.9
    • Affects Version/s: None
    • Component/s: Querying
    • None
    • Fully Compatible
    • ALL
    • Query 16 (06/24/16)
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      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" } }
      

            Assignee:
            David Hatch (Inactive)
            Reporter:
            Tess Avitabile (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: