-
Type: Bug
-
Resolution: Unresolved
-
Priority: 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.
- is related to
-
SERVER-26413 Hinting an incompatible partial index can return incomplete results
- Backlog
- related to
-
SERVER-62362 Hints are allowed on special indexes like 2d and text but lead to incorrect results
- Open
-
SERVER-26581 hinting index with different collation than query specifies should give an error or warning
- Closed