Take the shard key into account when choosing an index for distinct scan

    • 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

      In getDistinctNodeIndex(), we currently only look at the projection when choosing an index for a hand-crafted distinct scan. We should also take into account the shard key if shard filtering is requested. For an example, consider distinct("notShardKey") with the indexes notShardKey_1 and notShardKey_1_shardKey_1. The current heuristic picks the first index, forcing us to redundantly fetch. Note also that for $group queries, the shard key and the projection might not have any common fields, and we should only consider the query covered if it can cover both of them.

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

                Created:
                Updated: