summaryrefslogtreecommitdiff
path: root/jstests/core/stages_and_hash.js
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2014-02-19 12:45:53 -0500
committerMatt Kangas <matt.kangas@mongodb.com>2014-03-03 22:54:10 -0500
commit3660343e0b4627d2fee4afb89b74d32644d16d18 (patch)
treeffa571e0b73ce56d73c2ae23f458f0db772ef782 /jstests/core/stages_and_hash.js
parent9fae141a1f3fe652fa6002e47722c5ceb051cffb (diff)
downloadmongo-3660343e0b4627d2fee4afb89b74d32644d16d18.tar.gz
SERVER-12127 migrate js tests to jscore suite when not related to writes
Migrate js tests starting from j-z. Include SERVER-12920 Update use_power_of_2.js Signed-off-by: Matt Kangas <matt.kangas@mongodb.com>
Diffstat (limited to 'jstests/core/stages_and_hash.js')
-rw-r--r--jstests/core/stages_and_hash.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/jstests/core/stages_and_hash.js b/jstests/core/stages_and_hash.js
new file mode 100644
index 00000000000..42ae0c8e34d
--- /dev/null
+++ b/jstests/core/stages_and_hash.js
@@ -0,0 +1,42 @@
+t = db.stages_and_hashed;
+t.drop();
+
+var N = 50;
+for (var i = 0; i < N; ++i) {
+ t.insert({foo: i, bar: N - i, baz: i});
+}
+
+t.ensureIndex({foo: 1})
+t.ensureIndex({bar: 1})
+t.ensureIndex({baz: 1})
+
+// Scan foo <= 20
+ixscan1 = {ixscan: {args:{name: "stages_and_hashed", keyPattern:{foo: 1},
+ startKey: {"": 20}, endKey: {},
+ endKeyInclusive: true, direction: -1}}};
+
+// Scan bar >= 40
+ixscan2 = {ixscan: {args:{name: "stages_and_hashed", keyPattern:{bar: 1},
+ startKey: {"": 40}, endKey: {},
+ endKeyInclusive: true, direction: 1}}};
+
+// bar = 50 - foo
+// Intersection is (foo=0 bar=50, foo=1 bar=49, ..., foo=10 bar=40)
+andix1ix2 = {andHash: {args: { nodes: [ixscan1, ixscan2]}}}
+res = db.runCommand({stageDebug: andix1ix2});
+assert.eq(res.ok, 1);
+assert.eq(res.results.length, 11);
+
+// This should raise an error as we can't filter on baz since we haven't done a fetch and it's not
+// in the index data.
+andix1ix2badfilter = {andHash: {filter: {baz: 5}, args: {nodes: [ixscan1, ixscan2]}}};
+res = db.runCommand({stageDebug: andix1ix2badfilter});
+assert.eq(res.ok, 0);
+
+// Filter predicates from 2 indices. Tests that we union the idx info.
+andix1ix2filter = {andHash: {filter: {bar: {$in: [45, 46, 48]},
+ foo: {$in: [4,5,6]}},
+ args: {nodes: [ixscan1, ixscan2]}}};
+res = db.runCommand({stageDebug: andix1ix2filter});
+assert.eq(res.ok, 1);
+assert.eq(res.results.length, 2);