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

Optimize SBE stage builder type checking for $add

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Major - P3 Major - P3
    • 6.3.0-rc0
    • None
    • None
    • None
    • Fully Compatible
    • QE 2023-01-23
    • 35

    Description

      Currently SBE stage builder for $add generates code with a lot of redundant isDate checks because we are allowed to have Date in the list of arguments, but only one and there is no obvious way to check that.

      It looks like we can do it in two passes with only one isDate and isNumber check per argument.

      First pass:

      Let's create a local variable that will store the index of the first argument that is a Date or -1 if there is no dates.

      Let <dateIndex> =
      if <isDate(argument 0)> then 0
      else if <isDate(argument 1) then 1
      else ...
      else if <isDate(argument n-1)> then n - 1
      else
      -1. 

      Second pass:
      Each argument, except for the date found in previous pass must be a Number.

      if
      <0 != dateIndex and argument 0 is not a Number> or 
      <1 != dateIndex and argument 1 is not a Number> or 
      ...
      <n-1 != dateIndex and argument n-1 is not a Number> 
      then error 

      After that we can just add all the arguments without extra type checking.

      Performance improvement should be visible in sbe_expression_bm (I hope).

      Attachments

        Activity

          People

            ivan.fefer@mongodb.com Ivan Fefer
            ivan.fefer@mongodb.com Ivan Fefer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: