Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-32549

allow $expr with $in expression use a non-multikey index

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: 3.6.0
    • Fix Version/s: Backlog
    • Component/s: Aggregation Framework
    • Labels:
    • Case:

      Description

      Similarly to SERVER-31760 it's possible to rewrite $expr with $in expression to an indexable MatchExpression.

      Semantically

       {$expr:{$in:[ "value", [ "v1", "v2", "v3" ]] } } 

      is exactly equivalent to

       {"value":{$in:[ "v1", "v2", "v3"]}} 

      if value is not an array.

      If we restrict using an index for $expr $in expressions to non-multikey indexes/paths, then we will only get back matches from the index that are guaranteed to be correct semantically to the aggregation meaning of $in.

      This is also exactly equivalent query that can use any index and return only agg semantics:

      db.reviews.find({product_id:{$in:["hat","shirt"],$not:{$elemMatch:{$exists:true}}}})
      

      The second part prevents reaching into arrays for comparison.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              backlog-query-optimization Backlog - Query Optimization
              Reporter:
              asya Asya Kamsky
              Participants:
              Votes:
              23 Vote for this issue
              Watchers:
              36 Start watching this issue

                Dates

                Created:
                Updated: