-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework, Querying
-
Labels:None
-
Query Optimization
When optimizing an aggregation pipeline, we may coalesce multiple stages, swap stages, split stages into two, or eliminate stages entirely. When such an optimization occurs, we often step backwards in order to see whether this optimization allows us to perform yet another optimization step that was not previously possible. Although we are confident that as currently implemented, this process will always terminate, it seems like it could be easy to introduce a code change in the future that would prevent termination in some cases.
In order to make it trivial to prove that agg optimization always terminates, we should only be willing to perform at most some large maximum number of optimization steps. This would involve limiting the number of possible iterations here:
https://github.com/mongodb/mongo/blob/r3.4.0-rc0/src/mongo/db/pipeline/pipeline.cpp#L113-L116