[SBE] Executing $top in a $setWindowFields with an out-of-bounds window isn't consistent with classic

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 8.3.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • Fully Compatible
    • ALL
    • Hide

      Execute the following query, both in classic and SBE.

      db.test.drop()
      db.test.insert({a: 1})
      db.test.aggregate([
          { $setWindowFields: {
              "sortBy" : { "a" : 1 },
              "output" : {
                          "str" : {
                              "$top" : {
                                  "output" : "$a",
                                  "sortBy" : { "a" : 1 } 
                              },
                              "window" : { "documents" : [ "unbounded", -1 ] }
                          },
                      }
          }}
      ])

      Note that this query returns str: null in classic and no str field in SBE.

      Reminder: to force classic on mongosh, execute [1], to try SBE, execute [2].

      [1] db.adminCommand({setParameter: 1, internalQueryFrameworkControl: "forceClassicEngine"})

      [2] db.adminCommand({setParameter: 1, internalQueryFrameworkControl: "trySbeEngine"})

      Show
      Execute the following query, both in classic and SBE. db.test.drop() db.test.insert({a: 1}) db.test.aggregate([     { $setWindowFields: {         "sortBy" : { "a" : 1 },         "output" : {                     "str" : {                         "$top" : {                             "output" : "$a" ,                             "sortBy" : { "a" : 1 }                          },                         "window" : { "documents" : [ "unbounded" , -1 ] }                     },                 }     }} ]) Note that this query returns str: null in classic and no str field in SBE. Reminder: to force classic on mongosh, execute [1] , to try SBE, execute [2] . [1] db.adminCommand({setParameter: 1, internalQueryFrameworkControl: "forceClassicEngine"}) [2] db.adminCommand({setParameter: 1, internalQueryFrameworkControl: "trySbeEngine"})
    • QE 2025-09-15
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      What is happening

      Executing a $top operator inside a $setWindowFields with an [unbounded, -1] documents bounds won't return the same values in classic and SBE. Classic will return a null value, while SBE will return nothing (meaning that the expected field won't be present in the output).

      What should happen

      Classic and SBE queries should return the same results.

            Assignee:
            Felipe Goron Farinon
            Reporter:
            Felipe Goron Farinon
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: