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

Hinting sparse index without sparse-compatible predicate should be disallowed

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: Backlog
    • Component/s: Querying
    • Operating System:
      ALL

      Description

      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.
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              backlog-query-optimization Backlog - Query Optimization
              Reporter:
              rassi J Rassi
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated: