-
Type: Task
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Optimization
{$group: {_id: "$shardKey", accum: {$bottom: {sortBy: {notShardKey: 1}, output: "$shardKey"}}}}
results in a COLLSCAN when ran on a collection with a compound index on shardKey and notShardKey.
It looks like the issue here is that when we check if a sort can be provided by an index, we don't account for the distinct key. Normally the sort spec would have to be a prefix of the index key, but for queries like this, the index key prefix we want is actually `{...distinctKey, ...sortSpec}`.