[SERVER-70940] Use internal names during stage reordering to prevent ambiguity Created: 28/Oct/22  Updated: 18/Jan/23  Resolved: 18/Jan/23

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

Type: Bug Priority: Major - P3
Reporter: Jennifer Peshansky (Inactive) Assignee: Backlog - Query Optimization
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-66570 Timeseries pushes down metaField-proj... Closed
Assigned Teams:
Query Optimization
Operating System: ALL
Sprint: QO 2022-10-31, QO 2022-11-14, QO 2022-11-28, QO 2022-12-12, QO 2022-12-26, QO 2023-01-09
Participants:

 Description   

The cause of the linked BF is that the given query is ambiguous - it asks for a field from $obj and then modifies obj in the same $project:

db.coll.aggregate( [{$project: {"time": "$obj.date", "obj": {$unsetField: {field: "text", input: {k: "text2", v: "$tag.assistant"}}}}}, {$sort: {_id: 1}}, {$limit: 20}] )

As a result, without optimization, $obj.date is missing; but with optimization, $addFields is added before $_internalUnpackBucket as part of stage reordering, resulting in $obj.date returning a value.

After discussing with Chris and Katya, both confirmed that we should make the output match the output of the non-optimized case. Alberto's suggestion for achieving this was that the optimization that moves $addFields before $internalUnpackBucket should be using an internal name rather than "obj", like:

"$addFields:" (
        "kInternalName1" : {
...



 Comments   
Comment by Jennifer Peshansky (Inactive) [ 18/Jan/23 ]

Good point hana.pearlman@mongodb.com - I ran the original failing fuzzer test on master and it no longer fails. I'll mark this as fixed by SERVER-66570

Generated at Thu Feb 08 06:17:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.