Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-5436

Optimize special case of Any with constant array and field equals parameter in predicate

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 3.2.0
    • Affects Version/s: 3.1.0
    • Component/s: Linq
    • None
    • Fully Compatible
    • Dotnet Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      The following LINQ query:

      var obj = new[] { 1, 2, 3 };
      var queryable = collection.AsQueryable()
          .Where(x => obj.Any(y => x.X== y));
      

      is currently translated generically which results in MQL that is more complicated than necessary for this special case.

      In this particular special case where the parameters to `Any` are a constant array and predicate comparing a field to the predicate parameter, the following simpler (and more efficient) MQL can be generated:

      { $match : { X : { $in : [1, 2, 3] } } }
      

            Assignee:
            oleksandr.poliakov@mongodb.com Oleksandr Poliakov
            Reporter:
            robert@mongodb.com Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: