[CSHARP-1838] Merge multiple .Where() clauses to a single $match before querying Created: 25/Nov/16  Updated: 11/Jan/17  Resolved: 11/Jan/17

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: 2.3
Fix Version/s: None

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

Issue Links:
Duplicate
is duplicated by CSHARP-1887 Сombine all $match in one $match Closed
Backwards Compatibility: Fully Compatible

 Description   

My first issue here so please correct me if I make any mistakes posting it.

The aggregation framework that the 2.* driver maps to only uses indexes for the first match (https://docs.mongodb.com/v3.2/reference/operator/aggregation/match/).

I often pass aroung IQueryable to multiple layers in my applications that combine .Where(...) clauses to filter the result (depending on user input, access level etc).

The resulting query that the driver produces translates every .Where() clause to a $match. This results in poor performance since the indexes are only used for the first $match.

Would it be possible for the driver to combine these $match'es to a single $match?



 Comments   
Comment by Robert Stam [ 11/Jan/17 ]

Looks like the server implemented this optimization a long time ago, in version 2.6:

https://jira.mongodb.org/browse/SERVER-11184

Comment by Sten Blomstrand [ 05/Dec/16 ]

I what version did this change?

Comment by Robert Stam [ 30/Nov/16 ]

Have you tried this with the current version of the server?

The server is supposed to merge $match stages in which case it should not be necessary for any drivers to do that.

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