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

Generate unique fieldname for partitionBy expression

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.9.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Fully Compatible
    • Query Optimization 2021-02-22

      When parsing a $setWindowFields stage, we translate the partitionBy to a $sort stage. But $sort can only sort by a field, not an expression. So, if the partitionBy expression is not a field path, we move the expression to a $set stage.

      The translation looks roughly like this:

      {$setWindowFields: {partitionBy: {$add: ...}, ...} }
      =>
      {$set: {tmp: {$add ...} } }
      {$sort: {tmp: 1} }
      {$_internalSetWindowFields: {partitionBy: "$tmp", ...} }
      {$unset: 'tmp'}
      

      But this is incorrect if the input has a field named 'tmp' already. (The actual name we use is not "tmp" but something like "_internal_setWindowFields_partitionKey".)

      Instead, we should generate a random fieldname, like a UUID (although maybe we want to string-encode it more efficiently than the usual hexadecimal).

            Assignee:
            hartek.sabharwal@mongodb.com Hartek Sabharwal
            Reporter:
            david.percy@mongodb.com David Percy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: