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

$let should participate in constant folding

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None
    • Query Optimization

    Description

      When a $let variable simplifies to a constant, references to that variable should simplify to a constant too. For example, in

      {$match: {$expr:
        {$let: {
          vars: {upperBound: {$add: [2, 3]}},
          in: {$lt: ["$field", {$add: ["$$upperBound", 10]}]}
        }}
      }}
      

      This should simplify down to

      {$match: {$expr:
        {$lt: ["$field", 15]}
      }}
      

      which thanks to SERVER-39943 can be indexed.

      Possibly this is actually 2 separate optimizations:
      1. replace each occurrence of "$$upperBound" with 5
      2. remove the $let expression since $$upperBound is unused

      If some of the vars are constant and some are not, we can apply rule 1 but not rule 2.

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            david.percy@mongodb.com David Percy
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated: