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

Generate unique fieldname for partitionBy expression

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.9.0
    • Component/s: None
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Sprint:
      Query Optimization 2021-02-22

      Description

      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).

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: