[SERVER-24279] Sort provided from index does not respect query collation Created: 24/May/16  Updated: 14/Jul/16  Resolved: 17/Jun/16

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: 3.3.9

Type: Bug Priority: Major - P3
Reporter: Tess Avitabile (Inactive) Assignee: David Hatch
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Query 16 (06/24/16)
Participants:

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



 Comments   
Comment by Githook User [ 17/Jun/16 ]

Author:

{u'username': u'dhatch', u'name': u'David Hatch', u'email': u'david.hatch@mongodb.com'}

Message: SERVER-24279 Properly add sort when index does not respect query collation.
Branch: master
https://github.com/mongodb/mongo/commit/0f6df2c8668432e46738f554d4c0c061d2d0ded2

Comment by Tess Avitabile (Inactive) [ 02/Jun/16 ]

The first case in the description has been resolved.

Comment by Githook User [ 02/Jun/16 ]

Author:

{u'username': u'tessavitabile', u'name': u'Tess Avitabile', u'email': u'tess.avitabile@mongodb.com'}

Message: SERVER-24279 Sort on non-filter field provided by index must respect collation
Branch: master
https://github.com/mongodb/mongo/commit/f90053366eae561a564391f95978c9157065d05d

Generated at Thu Feb 08 04:05:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.