$unionWith sub-pipeline optimization runs without parent query settings

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Major - P3
    • 9.0.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • Fully Compatible
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      DocumentSourceUnionWith::optimize() invokes pipeline_optimization::optimizePipeline() on the sub-pipeline without first propagating QuerySettings from the parent ExpressionContext. As a result, optimizations that consult query settings (e.g. index hints, query framework selection, reject) operate on an empty QuerySettings instance for the unioned sub-pipeline at optimization time, even when the user has supplied query settings for the parent query.

      The settings are eventually copied at execution time in UnionWithStage::doGetNext() and (for explain) in DocumentSourceUnionWith::serialize(), but by then the sub-pipeline has already been optimized. During optimiztion any components requiring access to query settings fail.

      Expected Behavior. Sub-pipeline optimization within $unionWith should see the same QuerySettings as the parent pipeline, consistent with the propagation already performed at execution time in union_with_stage.cpp and at explain time in document_source_union_with.cpp.

      This ticket should fix this by initializing query settings on the sub-pipeline's ExpressionContext with the parent's settings before invoking optimizePipeline().

            Assignee:
            Matt Olma
            Reporter:
            Matt Olma
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: