Permalink
Browse files

Enhance orp test.

  • Loading branch information...
1 parent 4142a5b commit 871128194bbd5a605430d7924970f2d464ddfe69 @astaple astaple committed May 11, 2012
Showing with 22 additions and 4 deletions.
  1. +22 −4 jstests/orp.js
View
@@ -4,6 +4,12 @@
t = db.jstests_orp;
t.drop();
+function verifyExpectedQueryPlan( query ) {
+ explain = t.find( query ).explain();
+ assert.eq( 'BtreeCursor a_1', explain.clauses[ 0 ].cursor );
+ assert.eq( 'BasicCursor', explain.clauses[ 1 ].cursor );
+}
+
function checkAdvanceWithWriteOp( writeOp ) {
t.drop();
@@ -12,19 +18,31 @@ function checkAdvanceWithWriteOp( writeOp ) {
}
t.ensureIndex( { a:1 } );
- t.ensureIndex( { a:1, b:1 } );
- // The cursors traversed for this $or query will be a:1, $natural:1. The a:119 document will
+ // The presence of an index on the b field causes the query below to generate query plans for
+ // each $or clause iteratively rather than run a simple unindexed query plan.
+ t.ensureIndex( { c:1, b:1 } );
+
+ // The cursors traversed for this $or query will be a:1, $natural:1. The second clause will run
+ // as an unindexed scan because no index has b as its first field. The a:119 document will
// be the last document of the first clause and the first document of the (unindexed) second
// clause.
- writeOp( { $or:[ { a:{ $gte:0 } }, { b:2 } ] } );
+ query = { $or:[ { a:{ $gte:0 } }, { b:2 } ] };
+ verifyExpectedQueryPlan( query );
+ writeOp( query );
assert( !db.getLastError() );
+ assert.eq( 120, db.getLastErrorObj().n );
}
// Remove.
checkAdvanceWithWriteOp( function( query ) { t.remove( query ); } );
+// The documents were removed.
+assert.eq( 0, t.count() );
+assert.eq( 0, t.find().itcount() );
// Update - add a large field so the document will move.
big = new Array( 10000 ).toString();
-checkAdvanceWithWriteOp( function( query ) { t.update( query, { $set:{ z:big } }, false,
+checkAdvanceWithWriteOp( function( query ) { t.update( query, { $push:{ z:big } }, false,
true ); } );
+// The documents were updated.
+assert.eq( 120, t.count( { z:{ $size:1 } } ) );

0 comments on commit 8711281

Please sign in to comment.