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

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

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

      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@mongodb.com Katherine Wu (Inactive)
            Reporter:
            asya.kamsky@mongodb.com Asya Kamsky
            Votes:
            0 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved: