-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: 8.0.1
-
Component/s: None
-
None
-
Query Optimization
-
Fully Compatible
-
ALL
-
v8.0
-
-
(copied to CRM)
When performing a query that amounts to...
db.collection.find({ _id: { $in: [] }).hint({ _id: 1 })
... mongo 8 traverses the entire collection before reporting there are no results.
Under the hood, it seems that mongo 8 converts the find query to...
{ '$alwaysFalse': 1 }
... before executing it, where providing an index hint with the latter results in the full collection traversal.
We discovered this by noting a major performance regression in our application when migrating from mongo 7 to mongo 8. I don't believe that mongo 7 performs the above "under the hood" conversion, which means the query + hint works immediately as expected.
One can, of course, put in client-side logic to avoid making the above query since we know a-prior it will return no results, but it's fragile to assume this will always be done as it's reasonable for a dev to regard this as a trivial optimization.
It's also worth noting that we're aware hints should only be used if absolutely necessary, and have high confidence they're being used appropriately in our context.
- is duplicated by
-
SERVER-100269 EOF query plan with index hint performs full collection scan
-
- Closed
-
- is related to
-
SERVER-100269 EOF query plan with index hint performs full collection scan
-
- Closed
-
- related to
-
SERVER-70477 Optimizing expressions that are tautologically constant (e.g., `True` or `False`)
-
- Closed
-
-
SERVER-81863 Avoid a scan of either IDX or a collection if the filter is $alwaysFalse:
-
- Closed
-
-
SERVER-90828 Handle trivially false queries which attempt an index scan
-
- Closed
-