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

MatchExpression::getOptimizer() for $or/$and should collapse equivalent clauses

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 3.4.9
    • Component/s: Querying
    • Query Optimization

      The `$or` operator produces suboptimal results if the parameters in the list are exactly the same, at least when they're empty: `db.collection.count({$or: [ {}, {} ] })`

      The way I see it the query planner should be able to see that the parameters are exactly the same and simplify that.

      The query `db.collection.count({$or: [ {} ] })` produces a single COUNT stage whereas the more complex query with two empty params creates a SUBPLAN that uses COLLSCAN and only then is able to COUNT so the query is a lot slower.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            petazz Oskari Petas
            Votes:
            0 Vote for this issue
            Watchers:
            17 Start watching this issue

              Created:
              Updated:
              Resolved: