diff options
author | Ian Boros <puppyofkosh@gmail.com> | 2019-02-27 10:48:01 -0500 |
---|---|---|
committer | Ian Boros <puppyofkosh@gmail.com> | 2019-03-18 17:14:05 -0400 |
commit | 9950774372d4b47a0610fb810f49aeb274a3ff54 (patch) | |
tree | 63e760c47809c2a46ac12f23a4e08e30f24dd412 /jstests/noPassthroughWithMongod/ne_array_indexability.js | |
parent | a5138072e1bb731bbbc8612c21d4bb9c4cc98270 (diff) | |
download | mongo-9950774372d4b47a0610fb810f49aeb274a3ff54.tar.gz |
SERVER-39764 fix bug where $in is planned from cache incorrectly
Diffstat (limited to 'jstests/noPassthroughWithMongod/ne_array_indexability.js')
-rw-r--r-- | jstests/noPassthroughWithMongod/ne_array_indexability.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/ne_array_indexability.js b/jstests/noPassthroughWithMongod/ne_array_indexability.js new file mode 100644 index 00000000000..284389c1303 --- /dev/null +++ b/jstests/noPassthroughWithMongod/ne_array_indexability.js @@ -0,0 +1,45 @@ +/** + * Test that $ne: [] queries are cached correctly. See SERVER-39764. + */ +(function() { + const coll = db.ne_array_indexability; + coll.drop(); + + coll.createIndex({"obj": 1}); + coll.createIndex({"obj": 1, "abc": 1}); + + assert.commandWorked(coll.insert({obj: "hi there"})); + + function runTest(queryToCache, queryToRunAfterCaching) { + assert.eq(coll.find(queryToCache).itcount(), 1); + assert.eq(coll.find(queryToCache).itcount(), 1); + + const cacheEntries = + coll.aggregate([ + {$planCacheStats: {}}, + { + $match: { + isActive: true, + createdFromQuery: {query: queryToCache, sort: {}, projection: {}} + } + } + ]) + .toArray(); + assert.eq(cacheEntries.length, 1); + + assert.eq(coll.find(queryToRunAfterCaching).itcount(), 1); + + const explain = assert.commandWorked(coll.find(queryToRunAfterCaching).explain()); + // The query with the $ne: array should have the same queryHash, but a different + // planCacheKey. + assert.eq(explain.queryPlanner.queryHash, cacheEntries[0].queryHash); + assert.neq(explain.queryPlanner.planCacheKey, cacheEntries[0].planCacheKey); + } + + runTest({'obj': {$ne: 'def'}}, {'obj': {$ne: [[1]]}}); + + // Clear the cache. + assert.commandWorked(coll.runCommand('planCacheClear')); + + runTest({'obj': {$nin: ['abc', 'def']}}, {'obj': {$nin: [[1], 'abc']}}); +})(); |