| Steps To Reproduce: |
(function() {
|
"use strict";
|
|
db.test.drop();
|
|
const indexList = [
|
{
|
"a": 1,
|
},
|
{
|
"a": -1,
|
},
|
];
|
|
const indexOptions = [
|
{
|
partialFilterExpression: {a: {$gt: 0, $lt: 10}},
|
},
|
{},
|
];
|
|
const documentList = [
|
{
|
_id: 1,
|
"a": 1,
|
},
|
{
|
_id: 2,
|
"a": 11,
|
},
|
];
|
|
assert.commandWorked(db.test.insert(documentList));
|
|
for (let i = 0; i < indexList.length; i++) {
|
db.test.createIndex(indexList[i], indexOptions[i]);
|
}
|
|
// Populate cache for query shape {a: {$gt: <>, $lt: <>}}
|
assert.eq(db.test.aggregate({$match: {"a": {$gt: 0, $lt: 9}}}).itcount(), 1);
|
assert.eq(db.test.aggregate({$match: {"a": {$gt: 0, $lt: 9}}}).itcount(), 1);
|
|
// The plan cache key for this query ends up matching the first two, and thus incorrectly uses
|
// the partial IXSCAN plan. This should match the {_id: 2, a: 11} doc but does not if planned // from cache.
|
assert.eq(db.test.aggregate({$match: {"a": {$gt: 0, $lt: 12}}}).itcount(), 2);
|
})();
|
|