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

    XMLWordPrintable

    Details

    • Operating System:
      ALL
    • Case:

      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

              Assignee:
              backlog-server-query Backlog - Query Team
              Reporter:
              rassi J Rassi
              Participants:
              Votes:
              4 Vote for this issue
              Watchers:
              17 Start watching this issue

                Dates

                Created:
                Updated: