summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorDavis Haupt <davis.haupt@mongodb.com>2022-08-26 19:05:37 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-29 19:57:06 +0000
commit79cfcdd83eb6f64e164a588d0daf9bb873328b45 (patch)
tree9b49cdf2fb9c7a4a714f446a994ea72125182e87 /jstests
parente7580db9dd0ee6a77633ef2b918138b8afcb53a6 (diff)
downloadmongo-79cfcdd83eb6f64e164a588d0daf9bb873328b45.tar.gz
SERVER-68766 add server parameter to enable single value reduce optimizationr5.0.12-rc0r5.0.12
Diffstat (limited to 'jstests')
-rw-r--r--jstests/core/mr_single_reduce.js18
-rw-r--r--jstests/noPassthrough/mr_single_reduce_optimization.js29
2 files changed, 47 insertions, 0 deletions
diff --git a/jstests/core/mr_single_reduce.js b/jstests/core/mr_single_reduce.js
new file mode 100644
index 00000000000..28e66c71c72
--- /dev/null
+++ b/jstests/core/mr_single_reduce.js
@@ -0,0 +1,18 @@
+(function() {
+"use strict";
+const coll = db.bar;
+
+assert.commandWorked(coll.insert({x: 1}));
+
+const map = function() {
+ emit(0, "mapped value");
+};
+
+const reduce = function(key, values) {
+ return "reduced value";
+};
+
+const res = assert.commandWorked(
+ db.runCommand({mapReduce: 'bar', map: map, reduce: reduce, out: {inline: 1}}));
+assert.eq(res.results[0], {_id: 0, value: "reduced value"});
+}());
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);
+}());