In SERVER-60101, we are now able to eliminate the `mkbson` stage directly below a `group` stage. The query solution tree is of the form,
> db.t.explain().aggregate([{$group: {_id: {$add: ["$a", "$b", "$z"]}, s: {$sum: "$b"}}}]).queryPlanner.winningPlan
{
	"queryPlan" : {
		"stage" : "GROUP",
		"planNodeId" : 3,
		"inputStage" : {
			"stage" : "COLLSCAN",
			"planNodeId" : 1,
			"filter" : {
			},
			"direction" : "forward"
		}
	},
And the generated sbe plan is,
> db.t.explain().aggregate([{$group: {_id: "$a", s: {$sum: "$b"}}}]).queryPlanner.winningPlan.slotBasedPlan.stages
[3] mkbson s10 [_id = s6, s = s9] true false
[3] project [s9 = if (! exists (s8) || typeMatch (s8, 0x00000440), 0, doubleDoubleSumFinalize (s8))]
[3] group [s6] [s8 = aggDoubleDoubleSum (s7)]
[3] project [s7 = getField (s3, "b") #this is not needed
[3] project [s6 = fillEmpty (s5, null)]
[3] project [s5 = getField (s3, "a")] #this is not needed
[1] scan s3 s4 none none none none [] @"36bd379a-c864-43a6-9814-11025007ba75" true false
Each getField() on fields "a" and "b" will do a linear scan over the bson obj in slot s3. If we push the getFields into the scan stage we will be able to extract both "a" and "b" in a single pass. A rough plan after the optimization could be,
[3] mkbson s11 [_id = s7, p = s10] true false [3] project [s10 = if (! exists (s9) || typeMatch (s9, 0x00000440), 0, doubleDoubleSumFinalize (s8))] [3] group [s7] [s9 = aggDoubleDoubleSum (s8)] [3] project [s7 = fillEmpty (s6, null)] [1] scan s3 s4 none none none none [] @"3765f3f5-86ac-49e9-857f-d513b3112d74" true false lookup s6="a" s7="b"
- depends on
 - 
                    
SERVER-70509 [SBE] Pass input/output slots to UnionStage/SortedMergeStage in the correct order
-         
 - Closed
 
 -         
 - 
                    
SERVER-70476 Refactor buildSort() in "sbe_stage_builder.cpp"
-         
 - Closed
 
 -         
 
- is depended on by
 - 
                    
SERVER-69260 [SBE] Improve how optimizeFieldPaths() projects expressions to slots
-         
 - Closed
 
 -         
 - 
                    
SERVER-70972 Push simple getField() expressions into SBE scan stage
-         
 - Closed
 
 -         
 
- is duplicated by
 - 
                    
SERVER-60484 Optimize field paths more generally
-         
 - Closed
 
 -         
 - 
                    
SERVER-69542 Refactor how we track metadata slots
-         
 - Closed
 
 -         
 - 
                    
SERVER-69647 Refactor how $group optimizes itself in sbe_stage_builder
-         
 - Closed
 
 -