-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Optimization
The IDHACK is an optimization for _id lookups. It exploits the fact that _id ~always has a unique index; if the internal find cursor yields a document, there’s no need to iterate the cursor any more, or make an additional “step” in the query planner, which improves performance. This could be generalized to apply to any unique index where all properties of the index are given as simple equality values.
For example, given unique index {foo: 1, bar: 1}, a query {foo: 123, bar: "abc", baz: {$lt: 789}} would be able to use this enhanced IDHACK optimization.
A much more common case for us would be $in queries on _id, which I suspect is common to many users, since it's what you'd do to emulate joins. Today, an $in would require 2x the steps/cursor iterations compared to applying the IDHACK.