[SERVER-79514] Make value comparison consistent in MatchExpression Created: 31/Jul/23  Updated: 28/Nov/23  Resolved: 28/Nov/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.3.0-rc0

Type: Task Priority: Major - P3
Reporter: Alexander Ignatyev Assignee: Alexander Ignatyev
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
is documented by DOCS-16516 Investigate changes in SERVER-79514: ... Closed
Related
is related to SERVER-47664 Improved MatchExpression equivalence ... Backlog
Backwards Compatibility: Minor Change
Participants:

 Description   

equivalent() function should compare BSONElements consistently in comparison and $in operators.



 Comments   
Comment by Alexander Ignatyev [ 28/Nov/23 ]

Minor backward incompatible change.
TLDR: partial indexes with the same index keys and the same partial expressions compared using their collation are not allowed any more.

Partial filter expression used not to be validated using provided collation as a result, it was possible to create two equivalent indexes:

 

db.coll.createIndex({a: 1}, {name: "index0",{ locale: "en_US", strength: 1 }, partialFilterExpression: {b:"case"}};
db.coll.createIndex({a: 1}, {name: "index1", { locale: "en_US", strength: 1 }, partialFilterExpression: {b: "CASE"}};

However, only the first index index0 will be used to answer queries like

db.coll.find({a: 1, b: "case"}).collation({ locale: "en_US", strength: 1 });
db.coll.find({a: 1, b: "CASE"}).collation({ locale: "en_US", strength: 1 });
db.coll.find({a: 1, b: "Case"}).collation({ locale: "en_US", strength: 1 });

index1 would be never used.

After the change the second index1 will be prevented from creating with the following error:

MongoServerError: Index already exists with a different name: index0

Nothing changed for databases with existing duplicating partial indexes, the indexes will be kept and only the first created index will be used to serve the queries as it was before.

Comment by Githook User [ 27/Nov/23 ]

Author:

{'name': 'Alexander Ignatyev', 'email': 'alexander.ignatyev@mongodb.com', 'username': 'aligusnet'}

Message: SERVER-79514 Make value comparison consistent in MatchExpression

Use the collator to compare values of comparison match expressions.
Branch: master
https://github.com/mongodb/mongo/commit/1937ef27625420032c989369ad4abc5fb00e6d9a

Generated at Thu Feb 08 06:41:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.