-
Type:
Sub-task
-
Resolution: Duplicate
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Integration
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Overview
Implement DocumentSourceDocumentResultsAndMetadata::lowerToExecutable() and wire it into run_agg.cpp's prepareExecutorsForPipeline.
Background
\$_documentResultsAndMetadata is a transport container. During prepareExecutorsForPipeline in run_agg.cpp, if the pipeline begins with this stage it must be popped and replaced with directly executable stages before the pipeline runs.
Scope of Work
Implement DocumentSourceDocumentResultsAndMetadata::lowerToExecutable(Pipeline&):
- Pop the container from the pipeline front
- If _metadata == boost::none (elided): prepend _source directly — no Exchange needed
- Otherwise: construct an exec::agg::Exchange (policy kKeyRange on _streamType, two consumers) wrapping _source; create two DocumentSourceExchange consumers sharing the exchange via intrusive_ptr; append {{\$replaceRoot(
{newRoot: "\$payload"}
)}} after each consumer to unwrap user BSON from the {\$_streamType, payload} envelope
- For returnCursor = false (standalone): wrap consumer-1 and its \$replaceRoot in DocumentSourceSetVariableFromSubPipeline targeting Variables::kSearchMetaId; prepend consumer-0, \$replaceRoot, then \$setVar to the outer pipeline
Wire the call in run_agg.cpp:
if (auto* c = dynamic_cast(pipeline->peekFront())) c->lowerToExecutable(*pipeline);
Acceptance Criteria
- Metadata elided path: _source prepended with no Exchange overhead
- Standalone path: Exchange + $replaceRoot + $setVar wired correctly
- $$SEARCH_META is set before any downstream stage reads it
- Unit tests cover elided and non-elided paths
- depends on
-
SERVER-126007 Implement metadata elision optimization for $_internalDocumentResultsAndMetadata
-
- In Code Review
-
- duplicates
-
SERVER-126423 Register $_documentResultsAndMetadata exec::agg stage translation via REGISTER_AGG_STAGES_MAPPING
-
- In Code Review
-
- is depended on by
-
SERVER-126010 [M1 - Search Extension] Fix $lookup and $unionWith to invoke lowerToExecutable() for $_documentResultsAndMetadata in sub-pipelines
-
- Backlog
-