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.
- is duplicated by
-
SERVER-75079 Simplify boolean expressions before feeding them to the optimizer
- Closed
- is related to
-
SERVER-31639 Additional optimizations for MatchExpression::getOptimizer()
- Closed
-
SERVER-75079 Simplify boolean expressions before feeding them to the optimizer
- Closed
-
SERVER-49274 Coalesce scans of the same index in plans for rooted ORs
- Backlog
-
SERVER-22857 eliminate redundant conditions/clauses from query
- Closed
- related to
-
SERVER-60373 Duplicate predicates in query plan for time-series collection
- Closed