- 
    Type:
Improvement
 - 
    Resolution: Duplicate
 - 
    Priority:
Major - P3
 - 
    None
 - 
    Affects Version/s: None
 - 
    Component/s: None
 - 
    None
 
- 
        QE 2021-10-18, QE 2021-11-01
 - 
        None
 
- 
        None
 - 
        None
 - 
        None
 - 
        None
 - 
        None
 - 
        None
 
We can introduce a slot id to ExpressionFieldPath. If generateExpression find ExpressionFieldPath have a known slot id, it just generates a EVariable expression.
Two (top and bottom) $group stage builders should collaborate to be able to remove intermediary mkbson stage using the above mechanism.
- The topĀ GroupNode stage builder does not ask for the result slot if the bottom node is a GroupNode.
 - The top GroupNode stage builder builds the bottom node.
 - The bottom GroupNode does the same thing as usual except it does not add a mkbson stage at the end if the result slot is not requested. Instead, it returns field names and slots for _id and accumulator fields.
 - The top GroupNode stage builder looks up its fields in the returned field names and slots from the bottom GroupNode. If a field is found, then it updates ExpressionFieldPath with the returned slot id and let generateExpression's ExpressionFieldPath visitor know it.
 - ExpressionFieldPath visitor will generate a simple variable expression if it finds a slot id set at ExpressionFieldPath.
 
Update:
Introducing a slot id to ExpressionFieldPath would be more general optimization for field paths, not just for $group. Consider the above $group case as just an example. So, changed the title.
- duplicates
 - 
                    
SERVER-60234 Implement plumbing for getField() pushdown in the SBE stage builder
-         
 - Closed
 
 -