Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-95198

Take distinct key into account when analyzing sort requirement for distinct

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 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}`.

            Assignee:
            Unassigned Unassigned
            Reporter:
            henri.nikku@mongodb.com Henri Nikku
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: