getDistinctNodeIndex should consider both distinct fields and projections

XMLWordPrintableJSON

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

      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
            Reporter:
            Daniel Segel
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: