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

Short circuit $switch when any condition is constant

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 5.1.0-rc0
    • None
    • Fully Compatible
    • v5.2, v4.4, v4.2
    • Query Optimization 2021-06-14, Query Optimization 2021-06-28, Query Optimization 2021-07-12
    • 195

    Description

      There are several rules we can add to $switch to improve its constant folding:

      • When a case is a constant, and false, we can remove that case.
      • When a case is a constant, and true, we can turn that case into the default, and remove all subsequent cases.
      • When there are no cases, we can replace the $switch with its default.

      Alternatively, we could desugar $switch to chain of $cond expressions; then SERVER-55297 would have the same effect as the above three rules. This approach makes the rewrites simpler but results in more calls to evaluate().

      Either option would let $bucket take advantage of a $group-by-constant optimization, since $bucket desugars to $group + $switch. (Although I don't think we have a $group-by-constant optimization currently.)

      Attachments

        Issue Links

          Activity

            People

              naama.bareket@mongodb.com Naama Bareket
              david.percy@mongodb.com David Percy
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: