-
Type:
Task
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Execution
-
Fully Compatible
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Overview
Build CompactHashAggStage from the SBE stage builder for eligible $group stages, behind a new incremental rollout feature flag, featureFlagSbeCompactHashAgg (in_development, default off).
Selection rule
The stage builder chooses CompactHashAggStage for a scalar (non-block) $group when all of these hold:
- featureFlagSbeCompactHashAgg is enabled.
- allowDiskUse is false, since the compact stage cannot spill yet.
- Every accumulator of the $group has a compact implementation. Today only $sum does; {$sum: 1} and $count keep using HashAggStage. A $group with no accumulators qualifies.
Otherwise the stage builder builds HashAggStage as before. The shard side of a split $group uses the partial $sum output.
Scope of Work
- src/mongo/db/query/query_feature_flags.idl - new flag.
- src/mongo/db/query/stage_builder/sbe/ - compact accumulator builders, a new SbBlueprintCompactHashAgg blueprint node and its lowering, and the selection in gen_group.cpp.
- Stage builder unit tests and a new jstest, jstests/core/query/sbe/sbe_compact_group.js.
Acceptance Criteria
- With the flag off, plans and results do not change.
- With the flag on, an eligible $group run with allowDiskUse: false uses compact_group and returns results bitwise equal to HashAggStage.