diff options
author | Andrii Dobroshynski <andrii.dobroshynski@mongodb.com> | 2021-08-17 15:47:17 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-08-17 17:04:21 +0000 |
commit | 26bcd0f788184402ecefdc1221faf13a1f9b6e47 (patch) | |
tree | b02aea576ca6073006adab7dcaee6d0e8a4b7a23 /jstests | |
parent | 9f329ae9bb1c2f3e9e4eb0b0114c3eb6a3627d52 (diff) | |
download | mongo-26bcd0f788184402ecefdc1221faf13a1f9b6e47.tar.gz |
SERVER-57749 Optimize a projection expression prior to planning for 'find'
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/noPassthroughWithMongod/projection_optimizations.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/projection_optimizations.js b/jstests/noPassthroughWithMongod/projection_optimizations.js new file mode 100644 index 00000000000..57469299eb1 --- /dev/null +++ b/jstests/noPassthroughWithMongod/projection_optimizations.js @@ -0,0 +1,33 @@ +/** + * Test projections with $and in cases where optimizations could be performed. + */ +(function() { +"use strict"; + +load("jstests/aggregation/extras/utils.js"); +load('jstests/libs/analyze_plan.js'); + +const coll = db.projection_and; +coll.drop(); + +assert.commandWorked(coll.insert({_id: 0, a: 1})); +assert.commandWorked(coll.createIndex({a: 1})); + +function runFindWithProjection({filter = {}, projection, expected} = {}) { + const res = coll.find(filter, projection); + assertArrayEq(res.toArray(), expected); + return res; +} + +let result = runFindWithProjection({ + filter: {a: 1}, + projection: {_id: 0, a: 1, b: {$and: [false, "$b"]}}, + expected: [{a: 1, b: false}] +}); +// Query should be optimized and covered. +assert(isIndexOnly(db, getWinningPlan(result.explain().queryPlanner))); + +result = runFindWithProjection( + {projection: {a: {$and: ['$a', true, 1]}}, expected: [{_id: 0, a: true}]}); +assert(isCollscan(db, getWinningPlan(result.explain().queryPlanner))); +})(); |