$group can still use a distinct scan on a sparse index if an alternative index is available

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 8.3.0-rc0, 8.2.2
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • Fully Compatible
    • ALL
    • v8.2, v8.0, v7.0
    • Hide
      db.test.drop()
      db.test.insert({b: 5})
      db.test.createIndex({a: 1}, {sparse: true})
      db.test.createIndex({a: 1, b: 1})
      db.test.explain().aggregate({$group: {_id: "$a"}})
      // shows plan using distinct scan over sparse index, no rejected plans
      
      Show
      db.test.drop() db.test.insert({b: 5}) db.test.createIndex({a: 1}, {sparse: true }) db.test.createIndex({a: 1, b: 1}) db.test.explain().aggregate({$group: {_id: "$a" }}) // shows plan using distinct scan over sparse index, no rejected plans
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      It seems there is a case that SERVER-110423 did not fix. If there is an alternative index available then we can still use the sparse index. Note that if the compound index was not there then we would correctly use a collscan.

            Assignee:
            Militsa Sotirova
            Reporter:
            Militsa Sotirova
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: