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

Support block-based count end-to-end

    • 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
    • QE 2024-03-04
    • 35

      Given a simple timeseries collection:

      ./build/install/bin/mongod --setParameter featureFlagSbeFull=true --setParameter featureFlagTimeSeriesInSbe=true --setParameter logComponentVerbosity='{query: 5}'
      > 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 goal of this task is to get the following query working in block-processing mode (and to write a jstest that verifies it works):

      > db.coll.aggregate([{$project: {a: 1}}, {$match: {a: {$gte: 4}}}, {$count: "x"}]) 

       
      The generated plan is currently

      [5] project [s14 = makeBsonObj(MakeObjSpec([x], [x], Closed, RetNothing), null, true, s13)] 
      [4] group [s10] [s13 = sum(1)] spillSlots[s12] mergingExprs[sum(s12)] 
      [4] block_to_row blocks[s5] row[s11] s8 
      [4] project [s10 = null] 
      [2] filter {!(valueBlockNone(s8, true))} 
      [2] project [s8 = cellFoldValues_F(valueBlockFillEmpty(valueBlockGteScalar(cellBlockGetFlatValuesBlock(s7), 4L), false), s7)] 
      [2] ts_bucket_to_cellblock s2 pathReqs[s5 = ProjectPath(Get(_id)/Id), s6 = ProjectPath(Get(a)/Id), s7 = FilterPath(Get(a)/Traverse/Id)] 
      [1] filter {
          let [
              l101.0 = traverseP(s1, lambda(l102.0) { traverseP(getField(move(l102.0), \"max\"), lambda(l103.0) { getField(move(l103.0), \"a\") }, 1) }, 1) 
          ] 
          in 
              if (isArray(l101.0) ?: true) 
              then true 
              else (((l101.0 <=> 4L) >= 0) ?: ((exists(l101.0) && typeMatch(l101.0, -65)) >= true)) 
      } 
      [1] scan s2 s3 none none none none none none lowPriority [s1 = control] @\"be9e4531-c681-4da5-b7db-8326db4ad559\" true false
      

      Note: My understanding is that "count" gets converted to "sum(1)". Constant inputs for accumulators for BlockHashAggStage are not currently supported by the SBE stage builder, so this issue will need to be fixed / addressed somehow. It may be possible to implement special support just for "sum(1)", or we might have to implement general purpose support for constants by making the SBE stage builder convert them to MonoBlocks before passing them to BlockHashAggStage.

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

              Created:
              Updated:
              Resolved: