[SERVER-53974] Generate unique fieldname for partitionBy expression Created: 22/Jan/21  Updated: 29/Oct/23  Resolved: 18/Feb/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 4.9.0

Type: Improvement Priority: Major - P3
Reporter: David Percy Assignee: Hartek Sabharwal
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Query Optimization 2021-02-22
Participants:

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



 Comments   
Comment by Githook User [ 18/Feb/21 ]

Author:

{'name': 'Hartek Sabharwal', 'email': 'hartek.sabharwal@mongodb.com', 'username': 'tectonic8'}

Message: SERVER-53974 Generate unique field name for partitionBy expression
Branch: master
https://github.com/mongodb/mongo/commit/4b4be23e0991d902f8ebff1540369b4ac7f9489c

Generated at Thu Feb 08 05:32:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.