DISTINCT_SCAN in agg is only used when certain format of _id is specified

XMLWordPrintableJSON

    • Fully Compatible
    • v4.4, v4.2
    • Query 2020-06-29
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Implementation inĀ SERVER-9507 only works when specific format for _id in $group is used:

      // works
      db.newTest.explain(1).aggregate([
         {$sort:{valueDate:1}},
         {$group:{_id: "$valueDate", first: {$first: "$farmId"}}}
      ]).stages[0]["$cursor"]["executionStats"]
      {
              "executionSuccess" : true,
              "nReturned" : 2,
              "executionTimeMillis" : 0,
              "totalKeysExamined" : 2,
              "totalDocsExamined" : 2,
      ... }
      // doesn't work
      db.newTest.explain(1).aggregate([
        {$sort:{valueDate:1}},
        {$group:{_id: {v:"$valueDate"}, first: {$first: "$farmId"}}}
      ]).stages[0]["$cursor"]["executionStats"]
      {
              "executionSuccess" : true,
              "nReturned" : 5,
              "executionTimeMillis" : 0,
              "totalKeysExamined" : 10,
              "totalDocsExamined" : 5,
      ... }
       

              Assignee:
              Katherine Wu (Inactive)
              Reporter:
              Asya Kamsky
              Votes:
              0 Vote for this issue
              Watchers:
              14 Start watching this issue

                Created:
                Updated:
                Resolved: