[SERVER-60030] Wrong SBE PlanStage tree is generated for {$group: {_id: null, x: {$avg: "$b"}, y: {$addToSet: "$b"}}} Created: 16/Sep/21  Updated: 29/Oct/23  Resolved: 20/Sep/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 5.1.0-rc0

Type: Bug Priority: Major - P3
Reporter: Yoon Soo Kim Assignee: Yoon Soo Kim
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-59889 Add compatibility tests for $group pu... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: QE 2021-09-20, QE 2021-10-04
Participants:

 Description   

The following tree is generated

[3] mkbson s13 [_id = s6, x = s12, y = s9] true false
[3] project [s12 = if (! exists (s9) || typeMatch (s9, 0x00000440), null, doubleDoubleSumFinalize (s8) / s9)]
[3] group [s6] [s8 = aggDoubleDoubleSum (s7),
                s9 = sum (let [l1.0 = s7] if (! exists (l1.0) || typeMatch (l1.0, 0x00000440) || ! isNumber (l1.0), Nothing, 1)),
                s11 = addToSet (s10)]
[3] project [s10 = getField (s5, "b")]
[3] project [s7 = getField (s5, "b")]
[3] project [s6 = null]
[2] mkbson s5 s3 [b] keep [] true false
[1] scan s3 s4 none none none none [] @\"a83a82a5-a6d9-40fb-99e7-07e73544fb48\" true false "

The following tree SHOULD be generated

[3] mkbson s13 [_id = s6, x = s12, y = s11] true false
[3] project [s12 = if (! exists (s9) || typeMatch (s9, 0x00000440), null, doubleDoubleSumFinalize (s8) / s9)]
[3] group [s6] [s8 = aggDoubleDoubleSum (s7),
                s9 = sum (let [l1.0 = s7] if (! exists (l1.0) || typeMatch (l1.0, 0x00000440) || ! isNumber (l1.0), Nothing, 1)),
                s11 = addToSet (s10)]
[3] project [s10 = getField (s5, "b")]
[3] project [s7 = getField (s5, "b")]
[3] project [s6 = null]
[2] mkbson s5 s3 [b] keep [] true false
[1] scan s3 s4 none none none none [] @\"a83a82a5-a6d9-40fb-99e7-07e73544fb48\" true false "

This issue happens when the first accumulator generates multiple expressions and the second accumulator skips the finalization step.

Found an incompatibility with the classic engine. Here's a repro.

const tc = db.getCollection("testColl");
tc.insert({a: 1});
tc.aggregate([{$group: {_id: "$item", x: {$count: {}}}}]).toArray();
[ { "_id" : null, "x" : 1 } ]
db.adminCommand({setParameter: 1, internalQueryEnableSlotBasedExecutionEngine: true});
tc.aggregate([{$group: {_id: "$item", x: {$count: {}}}}]).toArray();
[ { "x" : 1 } ]



 Comments   
Comment by Vivian Ge (Inactive) [ 06/Oct/21 ]

Updating the fixversion since branching activities occurred yesterday. This ticket will be in rc0 when it’s been triggered. For more active release information, please keep an eye on #server-release. Thank you!

Generated at Thu Feb 08 05:48:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.