The old query system would prefer full index scans to collection scans in the case of covered queries. For example, with an index on field 'foo' consider the following query:
db.t.find({foo: {$exists: true}}, {_id: 0, foo: 1});
This query would be covered by the index, hence this test which asserts that explain.indexOnly is true.
The new query system does not try to construct full index scans for things like $exists and $nin, preferring a collection scan instead. This means that in the new system, a FETCH stage is required and the query is not covered. As a performance improvement, we could eliminate these fetches and make such queries covered.
- duplicates
-
SERVER-12557 $exists could use index
- Closed
- related to
-
SERVER-12869 Index null values and missing values differently
- Backlog