Generate covered projections with $expr

XMLWordPrintableJSON

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

      if we are using $expr, we don’t produce covered projections.

      If index on a is present,

      This will have fetch + projection simple
      db.test.explain().aggregate([{$match: {$expr: {$eq: ["$a", 1]}}}, {$project: {_id: 0, a: 1}}])

      But this will have projection covered:
      db.test.explain().aggregate([\{$match: {a: 1}}, \{$project: {_id: 0, a: 1}}])

      It looks like a problem with dependency analysis of $expr that can’t determine that we only need field “a” that can come from the index.

      In some cases we have to use $expr syntax. For example, in $lookup with pipelines.

              Assignee:
              [DO NOT USE] Backlog - Query Optimization
              Reporter:
              Ivan Fefer
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: