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

Implement plumbing for getField() pushdown in the SBE stage builder

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.2.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Fully Compatible
    • QE 2022-09-19, QE 2022-10-03, QE 2022-10-17, QE 2022-10-31
    • 5

      In SERVER-60101, we are now able to eliminate the `mkbson` stage directly below a `group` stage. The query solution tree is of the form,

      > db.t.explain().aggregate([{$group: {_id: {$add: ["$a", "$b", "$z"]}, s: {$sum: "$b"}}}]).queryPlanner.winningPlan
      {
      	"queryPlan" : {
      		"stage" : "GROUP",
      		"planNodeId" : 3,
      		"inputStage" : {
      			"stage" : "COLLSCAN",
      			"planNodeId" : 1,
      			"filter" : {
      
      			},
      			"direction" : "forward"
      		}
      	},
      

      And the generated sbe plan is,

      > db.t.explain().aggregate([{$group: {_id: "$a", s: {$sum: "$b"}}}]).queryPlanner.winningPlan.slotBasedPlan.stages
      [3] mkbson s10 [_id = s6, s = s9] true false
      [3] project [s9 = if (! exists (s8) || typeMatch (s8, 0x00000440), 0, doubleDoubleSumFinalize (s8))]
      [3] group [s6] [s8 = aggDoubleDoubleSum (s7)]
      [3] project [s7 = getField (s3, "b") #this is not needed
      [3] project [s6 = fillEmpty (s5, null)]
      [3] project [s5 = getField (s3, "a")] #this is not needed
      [1] scan s3 s4 none none none none [] @"36bd379a-c864-43a6-9814-11025007ba75" true false
      

      Each getField() on fields "a" and "b" will do a linear scan over the bson obj in slot s3. If we push the getFields into the scan stage we will be able to extract both "a" and "b" in a single pass. A rough plan after the optimization could be,

      [3] mkbson s11 [_id = s7, p = s10] true false
      [3] project [s10 = if (! exists (s9) || typeMatch (s9, 0x00000440), 0, doubleDoubleSumFinalize (s8))]
      [3] group [s7] [s9 = aggDoubleDoubleSum (s8)]
      [3] project [s7 = fillEmpty (s6, null)]
      [1] scan s3 s4 none none none none [] @"3765f3f5-86ac-49e9-857f-d513b3112d74" true false lookup s6="a" s7="b"
      

            Assignee:
            andrew.paroski@mongodb.com Drew Paroski
            Reporter:
            eric.cox@mongodb.com Eric Cox (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: