Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-60030

Wrong SBE PlanStage tree is generated for {$group: {_id: null, x: {$avg: "$b"}, y: {$addToSet: "$b"}}}

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 5.1.0-rc0
    • None
    • None
    • Fully Compatible
    • ALL
    • QE 2021-09-20, QE 2021-10-04

    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 } ]
      

      Attachments

        Issue Links

          Activity

            People

              yoonsoo.kim@mongodb.com Yoon Soo Kim
              yoonsoo.kim@mongodb.com Yoon Soo Kim
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: