summaryrefslogtreecommitdiff
path: root/jstests/core/index_partial_read_ops.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/core/index_partial_read_ops.js')
-rw-r--r--jstests/core/index_partial_read_ops.js142
1 files changed, 71 insertions, 71 deletions
diff --git a/jstests/core/index_partial_read_ops.js b/jstests/core/index_partial_read_ops.js
index 27fdb430fba..eba93a7ee23 100644
--- a/jstests/core/index_partial_read_ops.js
+++ b/jstests/core/index_partial_read_ops.js
@@ -8,75 +8,75 @@
load("jstests/libs/analyze_plan.js");
(function() {
- "use strict";
- var explain;
- var coll = db.index_partial_read_ops;
- coll.drop();
-
- assert.commandWorked(coll.ensureIndex({x: 1}, {partialFilterExpression: {a: {$lte: 1.5}}}));
- assert.writeOK(coll.insert({x: 5, a: 2})); // Not in index.
- assert.writeOK(coll.insert({x: 6, a: 1})); // In index.
-
- //
- // Verify basic functionality with find().
- //
-
- // find() operations that should use index.
- explain = coll.explain('executionStats').find({x: 6, a: 1}).finish();
- assert.eq(1, explain.executionStats.nReturned);
- assert(isIxscan(db, explain.queryPlanner.winningPlan));
- explain = coll.explain('executionStats').find({x: {$gt: 1}, a: 1}).finish();
- assert.eq(1, explain.executionStats.nReturned);
- assert(isIxscan(db, explain.queryPlanner.winningPlan));
- explain = coll.explain('executionStats').find({x: 6, a: {$lte: 1}}).finish();
- assert.eq(1, explain.executionStats.nReturned);
- assert(isIxscan(db, explain.queryPlanner.winningPlan));
-
- // find() operations that should not use index.
- explain = coll.explain('executionStats').find({x: 6, a: {$lt: 1.6}}).finish();
- assert.eq(1, explain.executionStats.nReturned);
- assert(isCollscan(db, explain.queryPlanner.winningPlan));
- explain = coll.explain('executionStats').find({x: 6}).finish();
- assert.eq(1, explain.executionStats.nReturned);
- assert(isCollscan(db, explain.queryPlanner.winningPlan));
-
- //
- // Verify basic functionality with the count command.
- //
-
- // Count operation that should use index.
- explain = coll.explain('executionStats').count({x: {$gt: 1}, a: 1});
- assert(isIxscan(db, explain.queryPlanner.winningPlan));
-
- // Count operation that should not use index.
- explain = coll.explain('executionStats').count({x: {$gt: 1}, a: 2});
- assert(isCollscan(db, explain.queryPlanner.winningPlan));
-
- //
- // Verify basic functionality with the aggregate command.
- //
-
- // Aggregate operation that should use index.
- explain = coll.aggregate([{$match: {x: {$gt: 1}, a: 1}}], {explain: true});
- assert(isIxscan(db, explain.queryPlanner.winningPlan));
-
- // Aggregate operation that should not use index.
- explain = coll.aggregate([{$match: {x: {$gt: 1}, a: 2}}], {explain: true});
- assert(isCollscan(db, explain.queryPlanner.winningPlan));
-
- //
- // Verify basic functionality with the findAndModify command.
- //
-
- // findAndModify operation that should use index.
- explain = coll.explain('executionStats')
- .findAndModify({query: {x: {$gt: 1}, a: 1}, update: {$inc: {x: 1}}});
- assert.eq(1, explain.executionStats.nReturned);
- assert(isIxscan(db, explain.queryPlanner.winningPlan));
-
- // findAndModify operation that should not use index.
- explain = coll.explain('executionStats')
- .findAndModify({query: {x: {$gt: 1}, a: 2}, update: {$inc: {x: 1}}});
- assert.eq(1, explain.executionStats.nReturned);
- assert(isCollscan(db, explain.queryPlanner.winningPlan));
+"use strict";
+var explain;
+var coll = db.index_partial_read_ops;
+coll.drop();
+
+assert.commandWorked(coll.ensureIndex({x: 1}, {partialFilterExpression: {a: {$lte: 1.5}}}));
+assert.writeOK(coll.insert({x: 5, a: 2})); // Not in index.
+assert.writeOK(coll.insert({x: 6, a: 1})); // In index.
+
+//
+// Verify basic functionality with find().
+//
+
+// find() operations that should use index.
+explain = coll.explain('executionStats').find({x: 6, a: 1}).finish();
+assert.eq(1, explain.executionStats.nReturned);
+assert(isIxscan(db, explain.queryPlanner.winningPlan));
+explain = coll.explain('executionStats').find({x: {$gt: 1}, a: 1}).finish();
+assert.eq(1, explain.executionStats.nReturned);
+assert(isIxscan(db, explain.queryPlanner.winningPlan));
+explain = coll.explain('executionStats').find({x: 6, a: {$lte: 1}}).finish();
+assert.eq(1, explain.executionStats.nReturned);
+assert(isIxscan(db, explain.queryPlanner.winningPlan));
+
+// find() operations that should not use index.
+explain = coll.explain('executionStats').find({x: 6, a: {$lt: 1.6}}).finish();
+assert.eq(1, explain.executionStats.nReturned);
+assert(isCollscan(db, explain.queryPlanner.winningPlan));
+explain = coll.explain('executionStats').find({x: 6}).finish();
+assert.eq(1, explain.executionStats.nReturned);
+assert(isCollscan(db, explain.queryPlanner.winningPlan));
+
+//
+// Verify basic functionality with the count command.
+//
+
+// Count operation that should use index.
+explain = coll.explain('executionStats').count({x: {$gt: 1}, a: 1});
+assert(isIxscan(db, explain.queryPlanner.winningPlan));
+
+// Count operation that should not use index.
+explain = coll.explain('executionStats').count({x: {$gt: 1}, a: 2});
+assert(isCollscan(db, explain.queryPlanner.winningPlan));
+
+//
+// Verify basic functionality with the aggregate command.
+//
+
+// Aggregate operation that should use index.
+explain = coll.aggregate([{$match: {x: {$gt: 1}, a: 1}}], {explain: true});
+assert(isIxscan(db, explain.queryPlanner.winningPlan));
+
+// Aggregate operation that should not use index.
+explain = coll.aggregate([{$match: {x: {$gt: 1}, a: 2}}], {explain: true});
+assert(isCollscan(db, explain.queryPlanner.winningPlan));
+
+//
+// Verify basic functionality with the findAndModify command.
+//
+
+// findAndModify operation that should use index.
+explain = coll.explain('executionStats')
+ .findAndModify({query: {x: {$gt: 1}, a: 1}, update: {$inc: {x: 1}}});
+assert.eq(1, explain.executionStats.nReturned);
+assert(isIxscan(db, explain.queryPlanner.winningPlan));
+
+// findAndModify operation that should not use index.
+explain = coll.explain('executionStats')
+ .findAndModify({query: {x: {$gt: 1}, a: 2}, update: {$inc: {x: 1}}});
+assert.eq(1, explain.executionStats.nReturned);
+assert(isCollscan(db, explain.queryPlanner.winningPlan));
})();