Support $unwind+$group to DISTINCT_SCAN optimization on sharded collections

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      SERVER-37715 added this optimization, but left out support for queries against sharded collections. Note that while shard key fields cannot be multikey, this optimization would still make sense when the shard key is the prefix of a compound index, and we are unwinding+grouping on some field that comes after it.

      E.g. 

      // ...shard collection on 'a'
      // 'b' is multikey, 'a' is not.
      assert.commandWorked(
          coll.insertMany([{a: 1, b: [1, 2]}, {a: 2, b: [3]}, {a: 3, b: 4}, {a: 4}]),
      );
      assert.commandWorked(coll.createIndex({a: 1, b: 1}));
      coll.aggregate([
          {$unwind: {path: "$b", preserveNullAndEmptyArrays: true}}, 
          {$group: {_id: "$b"}}
      ]);
      

      Should be able the use a DISTINCT_SCAN plan.

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

              Created:
              Updated: