• Type: Improvement
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      We could do the following rewrite:

      {$lookup: {as: "b"}}
      {$unwind: "b"}
      {$project: {b.value: 1}}
      | |
      v v
      {$lookup: {as: "b", pipeline: [{$project: {value: 1}}]}}
      {$unwind: "b"}
      

      + similar with renames and dotted paths where possible.

      We already have a similar rewrite on $match, to absorb the $match into the $lookup subpipeline.

      This $project rewrite will reduce the size of the returned data which has a positive performance impact, but also enable other optimisations, such as the projection pushdown, $match pushdown (including with computed fields), etc.

      A simple local test showed potential for 35% improvement when the foreign document is 16 KiB, seemingly from not having to produce a larger result (Classic engine), when we have an inclusion projection like the one above.

      This rewrite seems relevant at least until any $lookup can be lowered to SBE (assuming SBE will be not need this rewrite).

      This might partially address SERVER-26602 (although that ticket seems more general).

            Assignee:
            Unassigned
            Reporter:
            Vesko Karaganev
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: