-
Type: Bug
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: 3.6.6, 4.0.0
-
Component/s: Querying
-
Query Optimization
-
ALL
-
-
Query 2020-08-10
-
(copied to CRM)
For version 3.6, SERVER-13732 added an optimization for contained $or queries which causes the query planner to generate more efficient plans. This optimization can also cause additional indexed $or plans to be considered in 3.6 which were not considered in older versions of the MongoDB server. As an example, consider the query
find({a: 1, $or: [{b: 2, c: 2}, {b: 3, c: 3}]})
Suppose that the collection has indices {a: 1, c: 1} and {b: 1, c: 1}. Prior to 3.6, the query planner would generate two plans:
- An IXSCAN on {a: 1, c: 1} with bounds {a: [[1, 1]], c: [["MinKey", "MaxKey"]]}
- An OR plan with two IXSCANS on {b: 1, c: 1}.
With contained $or pushdown, the predicate "a:1" can be pushed into both branches of the $or. This allows the planner to additionally consider an OR plan with two IXSCANS on {a: 1, c: 1}, one with bounds {a: [[1, 1]], c: [[2, 2]]} and the other with bounds {a: [[1, 1]], c: [[3, 3]]}.
Typically, generating these extra plans has the benefit of allowing queries to be answered with tighter index bounds. However, in order to manage the potential combinatorial explosion of indexed OR plans, the planner imposes a limit on the number of plans generated for a particular $or node in the input query. This limit is configurable at startup and at runtime via the setParameter internalQueryEnumerationMaxOrSolutions, which has a default value of 10. The additional plans considered due to $or pushdown can cause the total number of plans to exceed internalQueryEnumerationMaxOrSolutions. This can inhibit generation of the best plan, thus causing a query to select a suboptimal indexed $or plan.
- is duplicated by
-
SERVER-38021 【query plans issue】inappropriate candidate plans are generated
- Closed
- is related to
-
SERVER-13732 Predicates in top-level implicit AND query not considered when generating index access plan for contained OR
- Closed
-
SERVER-47826 Server does not appropriately respect setting internalQueryEnumerationMaxOrSolutions to 0
- Closed
- related to
-
SERVER-50291 Add query knob to enumerate $or children in a different order
- Closed
- mentioned in
-
Page Loading...