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

Should be able to generate covered plan if the only dependency is the index key

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

      I was working with cheahuychou.mao@mongodb.com to investigate some ways to improve performance of an internal sharding query and we noticed that the first of these two generates a covered plan, and the second does not:

                  {"$project": {"_id": 0, "key": {"$meta": "indexKey"}}},
                  {
                      "$group": {
                          "_id": {"key0": {"$getField": {"field": "a.y.ii", "input": "$key"}}},
                          "frequency": {"$sum": 1}
                      }
                  },
      
                 {
                      "$group": {
                          "_id": {
                              "$let": {vars: {key: {"$meta": "indexKey"}},
                              "in": {
                                  "key0": {"$getField": {"field": "a.y.ii", "input": "$$key"}}}
                              }
                          },
                          "frequency": {"$sum": 1}
                      }
                  },
      

      Explains are attached.

        1. explain1.js
          7 kB
          Charlie Swanson
        2. explain2.js
          7 kB
          Charlie Swanson

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            charlie.swanson@mongodb.com Charlie Swanson
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: