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

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

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor - P4
    • Resolution: Unresolved
    • Affects Version/s: 3.4.9
    • Fix Version/s: Backlog
    • Component/s: Querying
    • Labels:

      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

              • Votes:
                0 Vote for this issue
                Watchers:
                12 Start watching this issue

                Dates

                • Created:
                  Updated: