Take distinct key into account when analyzing sort requirement for distinct

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • None
    • 3
    • 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}`.

            Assignee:
            Unassigned
            Reporter:
            Henri Nikku
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: