Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-83529

Generate covered projections with $expr

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

      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:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            ivan.fefer@mongodb.com Ivan Fefer
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: