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

Improve MatchExpression $or->$in rewrite to handle multiple fields

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.0.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • Fully Compatible
    • QO 2024-02-19, QO 2024-03-04
    • 51

      Currently the MatchExpression $or->$in rewrite is only capable of collapsing a single field with multiple equality disjunctions into a $in. For example,

       

      { $or: [
           { a: 10 },
           { b: 11 },
           { c: 12 },
           { d: 13 },
           { a: 14 }, 
           { b: 15 },
           { c: 16 },
           { d: 17 },
           { a: 18 },
           { b: 19 }
        ]
      } 

      is optimized to

       

       

      {
        $or: [
          { b: 11 },
          { b: 15 },
          { b: 19 },
          { c: 12 },
          { c: 16 },
          { d: 13 },
          { d: 17 },
          { a: { $in : [ 10, 14, 18 ] } }
        ]
      }

       

      This leads to an SBE plan with a large number of unnecessary comparisons. SBE is able to evaluate $in predicates more efficiently by using a hashset, and the interval builder is able to generate index bounds more easily on an $in list.

      These expressions can be further reduce by allowing the $or->$in rewrite to handle multiple fields.

      There are two high-value workloads (MatchExpressionWidePredicate and MatchExpressionWidePredicateWithDeepFieldpaths) which could be improved by this optimization.

            Assignee:
            militsa.sotirova@mongodb.com Militsa Sotirova
            Reporter:
            ben.shteinfeld@mongodb.com Ben Shteinfeld
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: