[SERVER-18449] Hinting sparse index without sparse-compatible predicate should be disallowed Created: 13/May/15  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: J Rassi Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: query-44-grooming
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-62362 Hints are allowed on special indexes ... Open
is related to SERVER-26413 Hinting an incompatible partial index... Backlog
Assigned Teams:
Query Optimization
Operating System: ALL
Participants:

 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.


Generated at Thu Feb 08 03:47:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.