diff options
author | Davis Haupt <davis.haupt@mongodb.com> | 2022-08-26 19:05:37 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-08-29 19:18:27 +0000 |
commit | 5133ed46464a264b8b6b3a08434978014783f3eb (patch) | |
tree | 256213fc3cb1433ebb7752d35e6837ef08d5582d /jstests/noPassthrough/mr_single_reduce_optimization.js | |
parent | ef2b8ad37963dfe259608319cd8d859ed3e3f3f1 (diff) | |
download | mongo-5133ed46464a264b8b6b3a08434978014783f3eb.tar.gz |
SERVER-68766 add server parameter to enable single value reduce optimization
Diffstat (limited to 'jstests/noPassthrough/mr_single_reduce_optimization.js')
-rw-r--r-- | jstests/noPassthrough/mr_single_reduce_optimization.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/jstests/noPassthrough/mr_single_reduce_optimization.js b/jstests/noPassthrough/mr_single_reduce_optimization.js new file mode 100644 index 00000000000..71ab924836b --- /dev/null +++ b/jstests/noPassthrough/mr_single_reduce_optimization.js @@ -0,0 +1,29 @@ +(function() { +"use strict"; +// See SERVER-68766. Verify that the reduce function is not run on a single value if the relevant +// flag is enabled. + +const conn = MongoRunner.runMongod({setParameter: {mrEnableSingleReduceOptimization: true}}); +const testDB = conn.getDB('foo'); +const coll = testDB.bar; + +assert.commandWorked(coll.insert({x: 1})); + +const map = function() { + emit(0, "mapped value"); +}; + +const reduce = function(key, values) { + return "reduced value"; +}; + +let res = assert.commandWorked( + testDB.runCommand({mapReduce: 'bar', map: map, reduce: reduce, out: {inline: 1}})); +assert.eq(res.results[0], {_id: 0, value: "mapped value"}); +assert.commandWorked(coll.insert({x: 2})); +res = assert.commandWorked( + testDB.runCommand({mapReduce: 'bar', map: map, reduce: reduce, out: {inline: 1}})); +assert.eq(res.results[0], {_id: 0, value: "reduced value"}); + +MongoRunner.stopMongod(conn); +}()); |