[SERVER-34846] Covered index with collated field returns incorrect result when collation not involved in match or sort Created: 04/May/18  Updated: 29/Oct/23  Resolved: 31/Jul/18

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: 3.4.17, 3.6.8, 4.0.2, 4.1.2

Type: Bug Priority: Critical - P2
Reporter: Asya Kamsky Assignee: Ian Boros
Resolution: Fixed Votes: 0
Labels: bkp, collation, neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.0, v3.6, v3.4, v3.2
Sprint: Query 2018-06-18, Query 2018-07-02, Query 2018-07-16, Query 2018-07-30, Query 2018-08-13
Participants:

 Description   

It appears that when covered index can be used, but collation isn't involved in match or sort then the strings from covered index query are returned without being looked up.

db.stringtest.insertOne({ int: 1, text: "hello world" });
db.stringtest.createIndex({ int: -1, text: -1 }, { collation: { locale: "en", strength: 1 }});
db.stringtest.find({ int: 1 }, { _id: 0, int: 1, text: 1 })
// expected result { int: 1, text: "hello world" }
// actual result
{"int" : 1, "text" : "71??E\u0004UEK?/" } 



 Comments   
Comment by Githook User [ 23/Aug/18 ]

Author:

{'name': 'Ian Boros', 'email': 'ian.boros@10gen.com'}

Message: SERVER-34846 Forwardize IndexBounds before intersectizing their OILs
Branch: v3.4
https://github.com/mongodb/mongo/commit/0f3e3998dd3a7627de274795a1a27e79b4de4783

Comment by Githook User [ 23/Aug/18 ]

Author:

{'name': 'Ian Boros', 'email': 'ian.boros@10gen.com'}

Message: SERVER-34846 Forwardize IndexBounds before intersectizing their OILs

(cherry picked from commit 7f442763c791873d74bea5c0c6e01812933deb38)
Branch: v4.0
https://github.com/mongodb/mongo/commit/1893820603fae7c79718ba9628a3fda3e6a36cd7

Comment by Githook User [ 23/Aug/18 ]

Author:

{'name': 'Ian Boros', 'email': 'ian.boros@10gen.com'}

Message: SERVER-34846 Forwardize IndexBounds before intersectizing their OILs

(cherry picked from commit 7f442763c791873d74bea5c0c6e01812933deb38)
Branch: v3.6
https://github.com/mongodb/mongo/commit/96f029ccab8b042db29f01671c03da86ea22b116

Comment by Githook User [ 31/Jul/18 ]

Author:

{'name': 'Ian Boros', 'email': 'ian.boros@10gen.com'}

Message: SERVER-34846 Forwardize IndexBounds before intersectizing their OILs
Branch: master
https://github.com/mongodb/mongo/commit/7f442763c791873d74bea5c0c6e01812933deb38

Comment by Asya Kamsky [ 04/May/18 ]

db.stringtest.find({ int: {$gte:1} }, { _id: 0, int: 1, text: 1 }).collation({ locale: "en", strength: 1 })
{ "int" : 4, "text" : "5EE/+Y1\u0004UEK?/" } 

Comment by Asya Kamsky [ 04/May/18 ]

Note that the behavior cannot be reproduced if sort is added EVEN if it's sort on int (with or without collation specified).

db.stringtest.find({ int: {$gte:1} }, { _id: 0, int: 1, text: 1 }).sort({int:1})
{ "int" : 1, "text" : "hello world" } 
db.stringtest.find({ int: {$gte:1} }, { _id: 0, int: 1, text: 1 }).sort({int:1}).collation({ locale: "en", strength: 1 }) 
{ "int" : 1, "text" : "hello world" }

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