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

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

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor - P4 Minor - P4
    • None
    • 3.4.9
    • Querying
    • Query Optimization

    Description

      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.

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            petazz Oskari Petas
            Votes:
            0 Vote for this issue
            Watchers:
            17 Start watching this issue

            Dates

              Created:
              Updated: