summaryrefslogtreecommitdiff
path: root/jstests/index_check6.js
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2012-02-14 09:30:08 -0800
committerAaron <aaron@10gen.com>2012-02-24 22:49:08 -0800
commitafc4e7fe813a753bf24414ff1385226d8ebbbd86 (patch)
tree8f9e15194fb18651a9c7e73635fe7a5c6176758b /jstests/index_check6.js
parentcb40560b1a085f9cd0e632b3e6879d6611df10dc (diff)
downloadmongo-afc4e7fe813a753bf24414ff1385226d8ebbbd86.tar.gz
4150 explain implementation checkpoint
Diffstat (limited to 'jstests/index_check6.js')
-rw-r--r--jstests/index_check6.js71
1 files changed, 37 insertions, 34 deletions
diff --git a/jstests/index_check6.js b/jstests/index_check6.js
index d7992a2e8f6..04f9ccbe7ed 100644
--- a/jstests/index_check6.js
+++ b/jstests/index_check6.js
@@ -12,12 +12,12 @@ for ( var age=10; age<50; age++ ){
assert.eq( 10 , t.find( { age : 30 } ).explain().nscanned , "A" );
assert.eq( 20 , t.find( { age : { $gte : 29 , $lte : 30 } } ).explain().nscanned , "B" );
-assert.eq( 18 , t.find( { age : { $gte : 25 , $lte : 30 }, rating: {$in: [0,9] } } ).explain().nscanned , "C1" );
-assert.eq( 23 , t.find( { age : { $gte : 25 , $lte : 30 }, rating: {$in: [0,8] } } ).explain().nscanned , "C2" );
-assert.eq( 28 , t.find( { age : { $gte : 25 , $lte : 30 }, rating: {$in: [1,8] } } ).explain().nscanned , "C3" );
+assert.eq( 18 , t.find( { age : { $gte : 25 , $lte : 30 }, rating: {$in: [0,9] } } ).hint( {age:1,rating:1} ).explain().nscanned , "C1" );
+assert.eq( 23 , t.find( { age : { $gte : 25 , $lte : 30 }, rating: {$in: [0,8] } } ).hint( {age:1,rating:1} ).explain().nscanned , "C2" );
+assert.eq( 28 , t.find( { age : { $gte : 25 , $lte : 30 }, rating: {$in: [1,8] } } ).hint( {age:1,rating:1} ).explain().nscanned , "C3" );
-assert.eq( 4 , t.find( { age : { $gte : 29 , $lte : 30 } , rating : 5 } ).explain().nscanned , "C" ); // SERVER-371
-assert.eq( 6 , t.find( { age : { $gte : 29 , $lte : 30 } , rating : { $gte : 4 , $lte : 5 } } ).explain().nscanned , "D" ); // SERVER-371
+assert.eq( 4 , t.find( { age : { $gte : 29 , $lte : 30 } , rating : 5 } ).hint( {age:1,rating:1} ).explain().nscanned , "C" ); // SERVER-371
+assert.eq( 6 , t.find( { age : { $gte : 29 , $lte : 30 } , rating : { $gte : 4 , $lte : 5 } } ).hint( {age:1,rating:1} ).explain().nscanned , "D" ); // SERVER-371
assert.eq.automsg( "2", "t.find( { age:30, rating:{ $gte:4, $lte:5} } ).explain().nscanned" );
@@ -31,37 +31,40 @@ for ( var a=1; a<10; a++ ){
}
}
-function doTest( s ) {
- sort = s;
-assert.eq.automsg( "1", "t.find( { a:5, b:5, c:5 } ).sort( sort ).explain().nscanned" );
-assert.eq.automsg( "2", "t.find( { a:5, b:5, c:{$gte:5,$lte:6} } ).sort( sort ).explain().nscanned" );
-assert.eq.automsg( "1", "t.find( { a:5, b:5, c:{$gte:5.5,$lte:6} } ).sort( sort ).explain().nscanned" );
-assert.eq.automsg( "1", "t.find( { a:5, b:5, c:{$gte:5,$lte:5.5} } ).sort( sort ).explain().nscanned" );
-assert.eq.automsg( "3", "t.find( { a:5, b:5, c:{$gte:5,$lte:7} } ).sort( sort ).explain().nscanned" );
-assert.eq.automsg( "4", "t.find( { a:5, b:{$gte:5,$lte:6}, c:5 } ).sort( sort ).explain().nscanned" );
- if ( s.b > 0 ) {
- assert.eq.automsg( "2", "t.find( { a:5, b:{$gte:5.5,$lte:6}, c:5 } ).sort( sort ).explain().nscanned" );
- assert.eq.automsg( "2", "t.find( { a:5, b:{$gte:5,$lte:5.5}, c:5 } ).sort( sort ).explain().nscanned" );
+function doQuery( count, query, sort, index ) {
+ assert.eq( count, t.find( query ).hint( index ).sort( sort ).explain().nscanned );
+}
+
+function doTest( sort, index ) {
+ doQuery( 1, { a:5, b:5, c:5 }, sort, index );
+ doQuery( 2, { a:5, b:5, c:{$gte:5,$lte:6} }, sort, index );
+ doQuery( 1, { a:5, b:5, c:{$gte:5.5,$lte:6} }, sort, index );
+ doQuery( 1, { a:5, b:5, c:{$gte:5,$lte:5.5} }, sort, index );
+ doQuery( 3, { a:5, b:5, c:{$gte:5,$lte:7} }, sort, index );
+ doQuery( 4, { a:5, b:{$gte:5,$lte:6}, c:5 }, sort, index );
+ if ( sort.b > 0 ) {
+ doQuery( 2, { a:5, b:{$gte:5.5,$lte:6}, c:5 }, sort, index );
+ doQuery( 2, { a:5, b:{$gte:5,$lte:5.5}, c:5 }, sort, index );
} else {
- assert.eq.automsg( "2", "t.find( { a:5, b:{$gte:5.5,$lte:6}, c:5 } ).sort( sort ).explain().nscanned" );
- assert.eq.automsg( "2", "t.find( { a:5, b:{$gte:5,$lte:5.5}, c:5 } ).sort( sort ).explain().nscanned" );
+ doQuery( 2, { a:5, b:{$gte:5.5,$lte:6}, c:5 }, sort, index );
+ doQuery( 2, { a:5, b:{$gte:5,$lte:5.5}, c:5 }, sort, index );
}
-assert.eq.automsg( "7", "t.find( { a:5, b:{$gte:5,$lte:7}, c:5 } ).sort( sort ).explain().nscanned" );
-assert.eq.automsg( "4", "t.find( { a:{$gte:5,$lte:6}, b:5, c:5 } ).sort( sort ).explain().nscanned" );
- if ( s.a > 0 ) {
- assert.eq.automsg( "2", "t.find( { a:{$gte:5.5,$lte:6}, b:5, c:5 } ).sort( sort ).explain().nscanned" );
- assert.eq.automsg( "2", "t.find( { a:{$gte:5,$lte:5.5}, b:5, c:5 } ).sort( sort ).explain().nscanned" );
- assert.eq.automsg( "3", "t.find( { a:{$gte:5.5,$lte:6}, b:5, c:{$gte:5,$lte:6} } ).sort( sort ).explain().nscanned" );
+ doQuery( 7, { a:5, b:{$gte:5,$lte:7}, c:5 }, sort, index );
+ doQuery( 4, { a:{$gte:5,$lte:6}, b:5, c:5 }, sort, index );
+ if ( sort.a > 0 ) {
+ doQuery( 2, { a:{$gte:5.5,$lte:6}, b:5, c:5 }, sort, index );
+ doQuery( 2, { a:{$gte:5,$lte:5.5}, b:5, c:5 }, sort, index );
+ doQuery( 3, { a:{$gte:5.5,$lte:6}, b:5, c:{$gte:5,$lte:6} }, sort, index );
} else {
- assert.eq.automsg( "2", "t.find( { a:{$gte:5.5,$lte:6}, b:5, c:5 } ).sort( sort ).explain().nscanned" );
- assert.eq.automsg( "2", "t.find( { a:{$gte:5,$lte:5.5}, b:5, c:5 } ).sort( sort ).explain().nscanned" );
- assert.eq.automsg( "3", "t.find( { a:{$gte:5.5,$lte:6}, b:5, c:{$gte:5,$lte:6} } ).sort( sort ).explain().nscanned" );
+ doQuery( 2, { a:{$gte:5.5,$lte:6}, b:5, c:5 }, sort, index );
+ doQuery( 2, { a:{$gte:5,$lte:5.5}, b:5, c:5 }, sort, index );
+ doQuery( 3, { a:{$gte:5.5,$lte:6}, b:5, c:{$gte:5,$lte:6} }, sort, index );
}
-assert.eq.automsg( "7", "t.find( { a:{$gte:5,$lte:7}, b:5, c:5 } ).sort( sort ).explain().nscanned" );
-assert.eq.automsg( "6", "t.find( { a:{$gte:5,$lte:6}, b:5, c:{$gte:5,$lte:6} } ).sort( sort ).explain().nscanned" );
-assert.eq.automsg( "6", "t.find( { a:5, b:{$gte:5,$lte:6}, c:{$gte:5,$lte:6} } ).sort( sort ).explain().nscanned" );
-assert.eq.automsg( "10", "t.find( { a:{$gte:5,$lte:6}, b:{$gte:5,$lte:6}, c:5 } ).sort( sort ).explain().nscanned" );
-assert.eq.automsg( "14", "t.find( { a:{$gte:5,$lte:6}, b:{$gte:5,$lte:6}, c:{$gte:5,$lte:6} } ).sort( sort ).explain().nscanned" );
+ doQuery( 7, { a:{$gte:5,$lte:7}, b:5, c:5 }, sort, index );
+ doQuery( 6, { a:{$gte:5,$lte:6}, b:5, c:{$gte:5,$lte:6} }, sort, index );
+ doQuery( 6, { a:5, b:{$gte:5,$lte:6}, c:{$gte:5,$lte:6} }, sort, index );
+ doQuery( 10, { a:{$gte:5,$lte:6}, b:{$gte:5,$lte:6}, c:5 }, sort, index );
+ doQuery( 14, { a:{$gte:5,$lte:6}, b:{$gte:5,$lte:6}, c:{$gte:5,$lte:6} }, sort, index );
}
for ( var a = -1; a <= 1; a += 2 ) {
@@ -70,8 +73,8 @@ for ( var a = -1; a <= 1; a += 2 ) {
t.dropIndexes();
var spec = {a:a,b:b,c:c};
t.ensureIndex( spec );
- doTest( spec );
- doTest( {a:-a,b:-b,c:-c} );
+ doTest( spec, spec );
+ doTest( {a:-a,b:-b,c:-c}, spec );
}
}
}