diff options
author | David Storch <david.storch@mongodb.com> | 2020-06-10 14:43:08 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-06-15 21:44:40 +0000 |
commit | 80f424c02df47469792917673ab7e6dd77b01421 (patch) | |
tree | 20a77cbd4acbedb26b4700f5f646700e795b2677 /jstests/core | |
parent | 1261db4a593fe06c5139fc0c9877c406d76b5bb4 (diff) | |
download | mongo-80f424c02df47469792917673ab7e6dd77b01421.tar.gz |
SERVER-48614 Fix plan cache discriminators for partial wildcard indexes
Previously, discrimination based on the partial filter
expression was done for all paths included in the wildcard
projection. This could lead to a situation where two queries
were erroneously assigned the same plan cache key.
The fix is to ensure that for wildcard indexes, partial
index discriminators are instead registered only for those
paths mentioned in the partial filter expression. Unlike
other kinds of wildcard index discriminators (e.g. handling
concerns of null equality or collation), the paths in the
partial filter expression are known a priori. Therefore,
discrimination based on the partial filter can be done in
the same way for wildcard and non-wildcard indexes.
Diffstat (limited to 'jstests/core')
-rw-r--r-- | jstests/core/wildcard_index_partial_index.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/jstests/core/wildcard_index_partial_index.js b/jstests/core/wildcard_index_partial_index.js index fa76746d9f9..7a0bd4c80ff 100644 --- a/jstests/core/wildcard_index_partial_index.js +++ b/jstests/core/wildcard_index_partial_index.js @@ -45,4 +45,19 @@ testPartialWildcardIndex({"$**": 1}, {partialFilterExpression: {a: {$lte: 1.5}}} // Case where the partial filter expression is on a field not included in the index. testPartialWildcardIndex({"x.$**": 1}, {partialFilterExpression: {a: {$lte: 1.5}}}); + +// This part of this test is designed to reproduce SERVER-48614. Historically, the correctness of +// the following queries was impacted by a bug in the plan caching system. +coll.drop(); +assert.commandWorked(coll.createIndex({"$**": 1}, {partialFilterExpression: {x: 1}})); +assert.commandWorked(coll.insert({x: 1})); + +// Produce an active plan cache entry for a query that can use the index. +for (let i = 0; i < 2; ++i) { + assert.eq(0, coll.find({x: 1, y: 1}).itcount()); +} +// Run a query with a similar shape, but which is not eligible to use the cached plan. This query +// should match the document in the collection (but would fail to match if it incorrectly indexed +// the $eq:null predicate using the wildcard index). +assert.eq(1, coll.find({x: 1, y: null}).itcount()); })(); |