summaryrefslogtreecommitdiff
path: root/jstests/core/batch_size.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/core/batch_size.js')
-rw-r--r--jstests/core/batch_size.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/jstests/core/batch_size.js b/jstests/core/batch_size.js
index 6cbc45dc803..5af59ab5391 100644
--- a/jstests/core/batch_size.js
+++ b/jstests/core/batch_size.js
@@ -73,3 +73,33 @@ var explain = t.find({a: {$gte: 50}}).sort({b: 1}).hint({a: 1}).limit(6).explain
assert.lte(explain.nscanned, 60, 'S');
assert.lte(explain.nscannedObjects, 60, 'T');
assert.eq(explain.n, 6, 'U');
+
+
+// -------
+
+
+// During plan ranking, we treat ntoreturn as a limit. This prevents us from buffering
+// too much data in a blocking sort stage during plan ranking.
+t.drop();
+
+// Generate big string to use in the object - 1MB+ String
+var bigStr = "ABCDEFGHIJKLMNBOPQRSTUVWXYZ012345687890";
+while (bigStr.length < 1000000) { bigStr = bigStr + "::" + bigStr; }
+
+// Insert enough documents to exceed the 32 MB in-memory sort limit.
+for (var i = 0; i < 40; i++) {
+ var doc = {x: 1, y: 1, z: i, big: bigStr};
+ t.insert(doc);
+}
+
+// Two indices needed in order to trigger plan ranking. Neither index provides
+// the sort order.
+t.ensureIndex({x: 1});
+t.ensureIndex({y: 1});
+
+// We should only buffer 3 docs in memory.
+var cursor = t.find({x: 1, y: 1}).sort({z: -1}).limit(3);
+assert.eq(39, cursor.next()["z"]);
+assert.eq(38, cursor.next()["z"]);
+assert.eq(37, cursor.next()["z"]);
+assert(!cursor.hasNext());