[SERVER-78147] Should be able to generate covered plan if the only dependency is the index key Created: 15/Jun/23  Updated: 22/Jun/23

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Charlie Swanson Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File explain1.js     File explain2.js    
Issue Links:
Related
related to SERVER-78105 Optimize the aggregation pipeline use... Closed
Assigned Teams:
Query Optimization
Participants:

 Description   

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.


Generated at Thu Feb 08 06:37:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.