summaryrefslogtreecommitdiff
path: root/jstests/queryoptimizer2.js
diff options
context:
space:
mode:
authorAntonin Kral <a.kral@bobek.cz>2012-08-29 20:54:51 +0200
committerAntonin Kral <a.kral@bobek.cz>2012-08-29 20:54:51 +0200
commit83957b73f9177f6e38bd5375bd93ca1f6a47188c (patch)
treef20b7d6ac9a9c64ff5bb6b5910a24abbb356b1d5 /jstests/queryoptimizer2.js
parent5071d203970edd4c995493d810abe20987e76fe9 (diff)
Imported Upstream version 2.2.0upstream/2.2.0
Diffstat (limited to 'jstests/queryoptimizer2.js')
-rw-r--r--jstests/queryoptimizer2.js71
1 files changed, 38 insertions, 33 deletions
diff --git a/jstests/queryoptimizer2.js b/jstests/queryoptimizer2.js
index af21e95cb03..6c7db13b4cb 100644
--- a/jstests/queryoptimizer2.js
+++ b/jstests/queryoptimizer2.js
@@ -1,62 +1,67 @@
t = db.queryoptimizer2;
+function debug( x ) {
+// printjson( x );
+}
+
function doTest( f1, f2 ) {
-t.drop()
-
-for( i = 0; i < 30; ++i ) {
- t.save( { a:2 } );
-}
+ t.drop()
+
+ for( i = 0; i < 30; ++i ) {
+ t.save( { a:2, z:1 } );
+ }
-for( i = 0; i < 30; ++i ) {
- t.save( { b:2 } );
-}
+ for( i = 0; i < 30; ++i ) {
+ t.save( { b:2, z:2 } );
+ }
-for( i = 0; i < 60; ++i ) {
- t.save( { c:2 } );
-}
+ for( i = 0; i < 60; ++i ) {
+ t.save( { c:2, z:3 } );
+ }
-t.ensureIndex( { a:1 } );
-t.ensureIndex( { b:1 } );
+ t.ensureIndex( { a:1 } );
+ t.ensureIndex( { b:1 } );
+ t.ensureIndex( { z:1 } );
-e = t.find( { b:2 } ).batchSize( 100 ).explain( true );
-assert.eq( null, e.oldPlan );
+ e = t.find( { b:2, z:2 } ).batchSize( 100 ).explain( true );
+ assert.eq( null, e.oldPlan );
-t.ensureIndex( { c:1 } ); // will clear query cache
+ t.ensureIndex( { c:1 } ); // will clear query cache
-f1();
+ f1();
-assert( t.find( { a:2 } ).batchSize( 100 ).explain( true ).oldPlan );
-assert( t.find( { b:2 } ).batchSize( 100 ).explain( true ).oldPlan );
+ assert( t.find( { a:2, z:1 } ).batchSize( 100 ).explain( true ).oldPlan );
+ assert( t.find( { b:2, z:2 } ).batchSize( 100 ).explain( true ).oldPlan );
-e = t.find( { c:2 } ).batchSize( 100 ).explain( true );
-// no pattern should be recorded as a result of the $or query
-assert.eq( null, e.oldPlan );
+ e = t.find( { c:2, z:3 } ).batchSize( 100 ).explain( true );
+ // no pattern should be recorded as a result of the $or query
+ assert.eq( null, e.oldPlan );
-t.dropIndex( { b:1 } ); // clear query cache
-for( i = 0; i < 15; ++i ) {
- t.save( { a:2 } );
-}
+ t.dropIndex( { b:1, z:2 } ); // clear query cache
+ for( i = 0; i < 15; ++i ) {
+ t.save( { a:2, z:1 } );
+ }
-f2();
-// pattern should be recorded, since > half of results returned from this index
-assert( t.find( { c:2 } ).batchSize( 100 ).explain( true ).oldPlan );
+ f2();
+ // pattern should be recorded, since we transitioned to the takeover cursor and had over 50 matches
+ assert( t.find( { c:2, z:3 } ).batchSize( 100 ).explain( true ).oldPlan );
}
doTest( function() {
- t.find( { $or: [ { a:2 }, { b:2 }, { c:2 } ] } ).batchSize( 100 ).toArray();
+ t.find( { $or: [ { a:2, z:1 }, { b:2, z:2 }, { c:2, z:3 } ] } ).batchSize( 100 ).toArray();
},
function() {
- t.find( { $or: [ { a:2 }, { c:2 } ] } ).batchSize( 100 ).toArray();
+ t.find( { $or: [ { a:2, z:1 }, { c:2, z:3 } ] } ).batchSize( 100 ).toArray();
}
);
doTest( function() {
- t.find( { $or: [ { a:2 }, { b:2 }, { c:2 } ] } ).limit( 100 ).count( true );
+ t.find( { $or: [ { a:2, z:1 }, { b:2, z:2 }, { c:2, z:3 } ] } ).limit(102).count( true );
},
function() {
- t.find( { $or: [ { a:2 }, { c:2 } ] } ).limit( 100 ).count( true );
+ t.find( { $or: [ { a:2, z:1 }, { c:2, z:3 } ] } ).limit(102).count( true );
}
);