| Steps To Reproduce: |
db.test2.drop()
|
var count=0;
|
var a=0, b=0, c=0;
|
for (; count < 10000; ++count){ a += 1; b +=1; c += 1; db.test2.save({"a": a%1000, "b": b%1000, "c": c}); }
|
db.test2.ensureIndex({a:1, _id:1})
|
db.test2.ensureIndex({a:1, b:1, c:1})
|
db.test2.getPlanCache().clear()
|
|
// Query that matches no document and puts bad plan in cache ({a:1, _id: 1})
|
db.test2.find({$or: [{a: 999999999, b: 500, c: 500},{a: 999999999, b: 999, c: 999}]})
|
|
// Query match using cached {a:1, _id: 1} index, resulting in poor performance. A choice of {a:1, b:1, c:1} would have provided much better performance.
|
db.test2.find({$or: [{a: 999, b: 999, c: 999},{a: 999, b: 999, c: 999}]})
|
db.test2.getPlanCache().getPlansByQuery({$or: [{a: 999, b: 999, c: 999},{a: 999, b: 999, c: 999}]})[0].details.solution
|
|
db.test2.getPlanCache().clear()
|
// The same query run after clearing the query cache chooses {a:1, b:1, c:1} demonstrating efficient execution
|
db.test2.find({$or: [{a: 999, b: 999, c: 999},{a: 999, b: 999, c: 999}]})
|
db.test2.getPlanCache().getPlansByQuery({$or: [{a: 999, b: 999, c: 999},{a: 999, b: 999, c: 999}]})[0].details.solution
|
|