-
Type:
Task
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Optimization
-
None
-
None
-
None
-
None
-
None
-
None
-
None
{$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}`.
- related to
-
SERVER-113145 Use distinct scan for $group+$top/$bottom and $sort when sort orders are compatible
-
- Open
-
-
SERVER-29444 Use a covered and streaming plan for $group, $sum:1 queries
-
- Backlog
-