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

Optimal index not chosen for query plan when many indexes match same prefix

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Duplicate
    • 2.6.0-rc1
    • None
    • Querying
    • Query Optimization
    • ALL

    Description

      The plan enumerator outputs 6 plans for the below query (one for each of the first 6 six indexes created), none of which use the 7th / most optimal index {a: 1, h: 1}.

      db.foo.ensureIndex({a: 1, b: 1});
      db.foo.ensureIndex({a: 1, c: 1});
      db.foo.ensureIndex({a: 1, d: 1});
      db.foo.ensureIndex({a: 1, e: 1});
      db.foo.ensureIndex({a: 1, f: 1});
      db.foo.ensureIndex({a: 1, g: 1});
      db.foo.ensureIndex({a: 1, h: 1});
       
      for (var i = 0; i < 10000; i++) {
          db.foo.insert({a: 1, h: i});
      }
       
      // Below assertion fails with "Error: [1] != [10000] are not equal"
      assert.eq(1, db.foo.find({a: 1, h: 1}).explain().nscanned);

      Attachments

        Issue Links

          Activity

            People

              backlog-query-optimization Backlog - Query Optimization
              rassi J Rassi
              Votes:
              12 Vote for this issue
              Watchers:
              34 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: