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

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

    XMLWordPrintable

Details

    • Improvement
    • Status: Backlog
    • Minor - P4
    • Resolution: Unresolved
    • 3.4.9
    • None
    • Querying

    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

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated: