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

distinct command with a winning plan of DISTINCT_SCAN returns null values, whereas COLLSCAN does not

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • ALL
    • Hide
      db.foo.drop()
      db.foo.insertMany([ { a: 1 }, { a: 1 }, { }, { a: 2 } ])
      db.runCommand({ distinct: "foo", key: "a" }).values
      // [ 1, 2 ]
      db.foo.createIndex({ a: 1 })
      db.runCommand({ distinct: "foo", key: "a" }).values
      // [ null, 1, 2 ]
      
      Show
      db.foo.drop() db.foo.insertMany([ { a: 1 }, { a: 1 }, { }, { a: 2 } ]) db.runCommand({ distinct: "foo" , key: "a" }).values // [ 1, 2 ] db.foo.createIndex({ a: 1 }) db.runCommand({ distinct: "foo" , key: "a" }).values // [ null , 1, 2 ]

      When executing a distinct command to identify distinct values within a collection, if the winning plan is a COLLSCAN the result set will exclude null values. If the winning plan is an IXSCAN (or a PROJECTION_COVERED/DISTINCT_SCAN) the result set will include the null values.

      I'm assuming this is by design, so if that's the case perhaps there's a documentation gap here.

            Assignee:
            chris.kelly@mongodb.com Chris Kelly
            Reporter:
            alex.bevilacqua@mongodb.com Alex Bevilacqua
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: