summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2010-08-31 20:33:58 -0700
committerAaron <aaron@10gen.com>2010-08-31 20:33:58 -0700
commita6e3b04263d32885d4462d4b34c7f77badef820e (patch)
tree2c4210bed65dc3b9a80cc824ffc0e75ee8d7124c /jstests
parentc296e87903f1235917102bb5ce96734c5596d325 (diff)
downloadmongo-a6e3b04263d32885d4462d4b34c7f77badef820e.tar.gz
SERVER-1207 be more conservative recording a successful query plan when part of an or clause
Diffstat (limited to 'jstests')
-rw-r--r--jstests/queryoptimizer2.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/jstests/queryoptimizer2.js b/jstests/queryoptimizer2.js
new file mode 100644
index 00000000000..af21e95cb03
--- /dev/null
+++ b/jstests/queryoptimizer2.js
@@ -0,0 +1,62 @@
+
+t = db.queryoptimizer2;
+
+function doTest( f1, f2 ) {
+
+t.drop()
+
+for( i = 0; i < 30; ++i ) {
+ t.save( { a:2 } );
+}
+
+for( i = 0; i < 30; ++i ) {
+ t.save( { b:2 } );
+}
+
+for( i = 0; i < 60; ++i ) {
+ t.save( { c:2 } );
+}
+
+t.ensureIndex( { a:1 } );
+t.ensureIndex( { b:1 } );
+
+e = t.find( { b:2 } ).batchSize( 100 ).explain( true );
+assert.eq( null, e.oldPlan );
+
+t.ensureIndex( { c:1 } ); // will clear query cache
+
+f1();
+
+assert( t.find( { a:2 } ).batchSize( 100 ).explain( true ).oldPlan );
+assert( t.find( { b: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 );
+
+t.dropIndex( { b:1 } ); // clear query cache
+for( i = 0; i < 15; ++i ) {
+ t.save( { a:2 } );
+}
+
+f2();
+// pattern should be recorded, since > half of results returned from this index
+assert( t.find( { c:2 } ).batchSize( 100 ).explain( true ).oldPlan );
+
+}
+
+doTest( function() {
+ t.find( { $or: [ { a:2 }, { b:2 }, { c:2 } ] } ).batchSize( 100 ).toArray();
+ },
+ function() {
+ t.find( { $or: [ { a:2 }, { c:2 } ] } ).batchSize( 100 ).toArray();
+ }
+ );
+
+doTest( function() {
+ t.find( { $or: [ { a:2 }, { b:2 }, { c:2 } ] } ).limit( 100 ).count( true );
+ },
+ function() {
+ t.find( { $or: [ { a:2 }, { c:2 } ] } ).limit( 100 ).count( true );
+ }
+ );