-
Type: Bug
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Optimization
Consider the below scenario:
data: [{mk: [1, 2, 3], notMk: 4}] index: {notMk: 1, mk: 1} query: {$group: {_id: "$notMk", acc: {$first: "$mk"}}}
The correct result (which we get without the index) would be
[ { _id: 4, acc: [ 1, 2, 3 ] } ]
But with the index, we get
[ { _id: 4, acc: 1 } ]
The planner will incorrectly use a distinct scan to cover the query because we currently allow it if there's no multikey field before the distinct key. When analyzing if the query can be covered by the scan, we should look at the projection, not just the distinct key.
- is related to
-
SERVER-94880 Ensure we never construct invalid distinct scans by hand
- In Code Review