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

Hinting sparse index without sparse-compatible predicate should be disallowed

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • Query Optimization
    • ALL

      If a user hints a sparse index without specifying a query predicate that is compatible with the sparse index, a whole index scan plan will be chosen on the hinted index. This whole index scan plan will unexpectedly miss documents from the result set that do not have any fields set from the index key pattern.

      These hints should instead be disallowed. Forbidding such hints is consistent with the query subsystem's effort to ensure that users consistently receive the same result set for a given query, independent of which query plan is chosen.

      Reproduce with the following shell snippet:

      db.foo.drop();
      db.foo.insert({});
      db.foo.ensureIndex({a: 1}, {sparse: true});
      assert.eq(1, db.foo.find().sort({a: 1}).hint({$natural: 1}).itcount()); // Succeeds as expected.
      assert.eq(1, db.foo.find().sort({a: 1}).hint({a: 1}).itcount()); // Fails: zero documents are returned.
      

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            rassi J Rassi
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated: