-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
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).
- related to
-
SERVER-89299 $setWindowFields aggregate commands generate unstable hashes
- Closed