-
Type:
Bug
-
Resolution: Duplicate
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Optimization
-
ALL
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Consider the following contrived pipeline
db.foo.explain().aggregate([
{$lookup: {from: "bar", localField: "_id", foreignField: "a", as: "as"}},
{$unwind: "$as"},
{$lookup: {from: "baz", localField: "as.a", foreignField: "_id", as: "as"}},
{$unwind: "$as"}
])
Note that both lookups overwrite the same “as” field. This query tasserts with "Self edges are not permitted” even though I don’t believe there are any self edges here.
The join graph should look like this, I believe (Apologies for the Jira formatting).
Foo | (foo._id == bar.a) Bar | (bar._a == baz._id) Baz
When I change the name of the “as” field used in the second lookup/unwind pair, we succeed in optimizing. I think this may be an issue with our path resolver.
We should be careful with how we optimize this query, because the output should contain the “as” field from the result of the second $lookup, not the first $lookup (or the “as” field from the “foo” collection, if one exists).
Should this be eligible for re-ordering at all?
- duplicates
-
SERVER-113227 Add logic to bail out for join-reordering for conflicting as fields
-
- Needs Scheduling
-