-
Type:
Sub-task
-
Resolution: Unresolved
-
Priority:
Major - P3
-
Affects Version/s: None
-
Component/s: None
-
Query Integration
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Overview
When $$SEARCH_META is not referenced by any downstream stage, there is no need to produce or transport a metadata stream. This ticket implements the optimization that detects this case and suppresses metadata computation.
Background
Skipping metadata computation matters because facet collection in mongot is not cheap. Without this optimization, every $search query would pay the cost of generating metadata regardless of whether any stage in the pipeline reads $$SEARCH_META.
Scope of Work
- Implement DocumentSourceDocumentResultsAndMetadata::optimizeAt(): scans subsequent pipeline stages for $$SEARCH_META variable references via addVariableRefs()
- If no references are found, set _metadata = boost::none and call skip_stream(kMetadataResult) on the extension's logical stage
- When getExpCtx()-> getNeedsMerge()=true (shard path), suppress elision unconditionally: the router — not the shard — decides whether metadata is needed
Acceptance Criteria
- $$SEARCH_META reference downstream: metadata retained
- No $$SEARCH_META reference downstream: metadata elided, skip_stream called on extension
- getExpCtx()-> getNeedsMerge() = true: elision suppressed regardless of downstream references
- Unit tests cover all three cases
- depends on
-
SERVER-126014 [M1 - Search Extension] Add skip_stream to MongoExtensionLogicalAggStageVTable
-
- Closed
-
-
SERVER-126006 [Server] Implement $_internalDocumentResultsAndMetadata stage and supporting exec machinery
-
- In Progress
-
- is depended on by
-
SERVER-126009 [M1 - Search Extension] Implement lowerToExecutable() and invoke from run_agg.cpp
-
- Closed
-
-
SERVER-126008 [M1 - Search Extension] Implement $_documentResultsAndMetadata compilation and standalone execution workflow
-
- Backlog
-