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

Support block-based $group with $avg end-to-end; integration and unit tests

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.0.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • Fully Compatible
    • 35

      Given a simple timeseries collection:

      ./build/install/bin/mongod --setParameter featureFlagSbeFull=true
      > db.coll.drop()
      > db.createCollection("coll", {timeseries: {timeField: "t"}})
      > db.coll.insert({t: new Date(), a: 4, b: 7, c: 5})
      > db.coll.insert({t: new Date(), a: 2, b: 9, c: 8})
      > db.coll.insert({t: new Date(), a: 3, b: 1, c: 6})
      

      the goals of this task are to make the following query work in block-processing mode and to write a jstest that verifies it works:

      db.coll.aggregate([{$project: {a: 1}}, {$group: {_id: null, x: {$avg : "$a"}}}], {allowDiskUse: false})

      Note that block processing is not yet supported with allowDiskUse: true, which has been the default since 6.0. This is being addressed in SERVER-84781.

      Before this task the SBE plan for this query is

      "slotBasedPlan" : {     
      "slots" : "$$RESULT=s14 env: { s5 = Nothing (nothing) }", 
      "stages" : " 
      [3] project [s14 = newBsonObj(\"_id\", s6, \"x\", s13)]
      [3] project [s13 = 
          if (s12 == 0ll) 
          then null 
          else (doubleDoubleSumFinalize(s11) / s12) 
      ]  
      [3] group [s6] [s11 = aggDoubleDoubleSum(s8), s12 = sum( 
          if ((typeMatch(s8, 1088) ?: true) || !(isNumber(s8)))
          then 0ll
          else 1ll
      )] spillSlots[s9, s10] mergingExprs[aggMergeDoubleDoubleSums(s9), sum(s10)]
      [3] block_to_row blocks[s3, s4] row[s7, s8]
      [3] project [s6 = null]
      [2] ts_bucket_to_cellblock s1 pathReqs[s3 = ProjectPath(Get(_id)/Id), s4 = ProjectPath(Get(a)/Id)]
      [1] scan s1 s2 none none none none none none lowPriority [] @\"136d26ac-0c66-4e1c-8eb6-ad0b089ce557\" true false "
      }                       
      

      where the sum of aggregated numeric values is in s11 and the count of these is in s12. If the denominator is non-zero, these are divided to produce the average in s13, else the average (s13) is set to null.

      The integration test written for this ticket should verify both correctness and that $avg actually uses the block processing code path where expected.

            Assignee:
            kevin.cherkauer@mongodb.com Kevin Cherkauer
            Reporter:
            andrew.paroski@mongodb.com Drew Paroski
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: