-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Optimization
-
ALL
-
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Join optimization can return incorrect results when a $lookup uses a base collection dotted localField, and a later $lookup writes to the same top-level path via as.
In the attached repro, the original pipeline first evaluates localField: "a.x" against the base document, where base.a.x == 1, then later embeds another lookup result at as: "a". Without join optimization, the pipeline returns one document.
With join optimization enabled and the joins reordered, the as: "a" lookup runs before the lookup whose predicate was resolved from base.a.x. The physical predicate still evaluates raw path "a.x", so it reads the newly embedded foreign document’s a.x == -1 instead of the original base field. The lookup then fails to match and returns zero documents.
Expected: reordered join plans preserve the original meaning of base localField paths.
Actual: reordered plan can evaluate the path after it has been shadowed by an embedded lookup result, producing incorrect results.