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

Generate covered projections with $expr

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Duplicate
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None
    • Query Optimization

    Description

      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.

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            ivan.fefer@mongodb.com Ivan Fefer
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: