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

Constant folding of n-ary math operation doesn't optimize operation as binary tree was doing

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • ALL
    • QE 2025-05-12
    • 200
    • None
    • 3
    • TBD
    • None
    • None
    • None
    • None
    • None
    • None

      An operation like ($field + 1 + 1 + .... 1) where the number of constants were enough to trigger the building of a binary tree used to be optimized into a reduced set of operations because the binary nodes involving constants were precomputed into a new constant. The final expression contained just log(n) operations, e.g. (((($field + 1) + 2) + 4) ...)
      When an n-ary operation is created, we precompute only the leading operations, and stop as soon as we find the non-constant operand, generating a much higher number of operations, with degraded performance.

            Assignee:
            alberto.massari@mongodb.com Alberto Massari
            Reporter:
            alberto.massari@mongodb.com Alberto Massari
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: