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

getDistinctNodeIndex should consider both distinct fields and projections

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.1.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • Fully Compatible
    • QO 2024-10-28

      When running:

      coll.aggregate([{$group: {_id: "$a", accum: {$first: "$b"}}}])

      on a collection that contains indexes: {a_1, b_1, a_1_b_1}, the multiplanner always picks a scan on `a_1` + FETCH. 

      The multiplanner does not even consider using a_1_b_1, which would avoid the FETCH entirely. 

      It seems that we only consider the distinct field here when trying to pick the index with the fewest fields. Instead, we should also account for any projections in that function.

      Add a corresponding test in distinct_aggregation_multiplanning_md.js

            Assignee:
            daniel.segel@mongodb.com Daniel Segel
            Reporter:
            daniel.segel@mongodb.com Daniel Segel
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: