[CSHARP-4116] Optimize { $expr : true } to { } Created: 29/Mar/22  Updated: 04/May/22  Resolved: 29/Mar/22

Status: Closed
Project: C# Driver
Component/s: LINQ3
Affects Version/s: None
Fix Version/s: 2.15.1

Type: Improvement Priority: Major - P3
Reporter: James Kovacs Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-65049 Optimize away { $expr : true } in $ma... Closed
Backwards Compatibility: Fully Compatible

 Description   

Consider the following LINQ:

var dog1 = "dog";
var dog2 = "dog";
var query = coll.AsQueryable().Where(x => dog1 == dog2);

This will render the following MQL because we know client-side at runtime that the expression evaluates to true.

[ { $match : { $expr : true } }]

We should optimize this to the equivalent and faster:

[ { $match : { } }]



 Comments   
Comment by Githook User [ 04/May/22 ]

Author:

{'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}

Message: CSHARP-4116: Optimize

{ $expr : true }

to { }.
Branch: v2.15.x
https://github.com/mongodb/mongo-csharp-driver/commit/3eb0282a4f0bdd79f6f32eb182e40c92fd47b6df

Comment by Githook User [ 29/Mar/22 ]

Author:

{'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}

Message: CSHARP-4116: Optimize

{ $expr : true }

to { }.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/931e6124d720adb49d3278003541d2b6831c630c

Comment by Robert Stam [ 29/Mar/22 ]

Also optimize 

{ $match : { $expr : false } }

 to

{ $match : { _id : { $type : -1 } } }

 

Generated at Wed Feb 07 21:47:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.