-
Type: Improvement
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.4.6
-
Component/s: Querying
-
None
Given indexes:
{ a: 1, b: 1 }and
{ a: 1, c: 1 }, a range query on 'a' with a projection on
{ a: 1, c: 1, _id: 0 }will choose the non-covering index
{ a: 1, b: 1 }when it should choose the covering index
{ a: 1, c: 1 }.
This happens because the optimizer doesn't consider the projection when selecting a plan, so it chooses the first plan that seems optimal (which is a: 1, b: 1 because that index appears first in the list of indexes for the namespace).
To reproduce:
db.a.ensureIndex(
)
db.a.ensureIndex(
)
db.a.insert(
)
db.a.find({ a:
},
{ a: 1, c: 1, _id: 0 })
The current work-around is to add a hint for the proper covering index. It would be neat if the correct index was chosen without a hint, though.
- duplicates
-
SERVER-2109 Query optimizer should pick plans that can use covered indexes
- Closed