[SERVER-47765] 4.0 Only: Make variables declared above DocumentSourceGraphLookup available within Created: 24/Apr/20  Updated: 29/Oct/23  Resolved: 01/May/20

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

Type: Task Priority: Major - P3
Reporter: James Wahlin Assignee: James Wahlin
Resolution: Fixed Votes: 0
Labels: greenerbuild, qopt-team
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-47893 Add test confirming that variables de... Closed
Backwards Compatibility: Fully Compatible
Participants:
Linked BF Score: 33

 Description   

This issue impacts the MongoDB 4.0 branch only.

This following was added which fixes in 4.2 as part of implementing $$NOW and $$CLUSTER_TIME:
https://github.com/mongodb/mongo/blob/fe855c5d116316c50905cf5900c23801fd0c6f68/src/mongo/db/pipeline/expression_context.cpp#L190-L191

Without this copy, a $expr with the "restrictSearchWithMatch" $graphLookup argument will not have access to variables defined in a parent $lookup stage.

When doing this work, we should confirm whether there is identical code in DocumentSourceLookup that can be removed.



 Comments   
Comment by Githook User [ 01/May/20 ]

Author:

{'name': 'James Wahlin', 'email': 'james@mongodb.com', 'username': 'jameswahlin'}

Message: SERVER-47765 Make variables declared above DocumentSourceGraphLookup available within
Branch: v4.0
https://github.com/mongodb/mongo/commit/265c4da7b3a9b97d40054e9d4da8ad75c4aca8a0

Comment by Craig Homa [ 28/Apr/20 ]

Hey james.wahlin, do you feel this is QE or QO work?

Comment by James Wahlin [ 24/Apr/20 ]

The following fails on 4.0 due to "foo" no being avaialbe for reference within the $graphLookup stage. It passes on MongoDB version 4.2 and later:

db.a.drop();
db.b.drop();
 
db.a.insert({});
db.b.insert({});
 
db.a.aggregate([{$lookup: {from: "b", let: {foo: 1}, pipeline: [
                          {$graphLookup: {from: "a", 
                              startWith: 1, 
                              connectFromField: "c",
                              connectToField: "d", 
                              as: "array",
                              depthField: "e",
                              restrictSearchWithMatch: {$expr: "$$foo"}}}
            ], 
        as: "array"}}]);

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