diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-11-10 16:22:04 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-11-10 16:22:04 -0500 |
commit | af8370b1e2ff5681858b855f0cb816e9197b1230 (patch) | |
tree | 0daaf7a2f8e0cbf7636ed365908cfe6a54909595 /jstests/sharding/limit_push.js | |
parent | 5a9526231e9a541adfae8e03b33dc1ba33cc76de (diff) | |
download | mongo-af8370b1e2ff5681858b855f0cb816e9197b1230.tar.gz |
fix limit on explain SERVER-1896
Diffstat (limited to 'jstests/sharding/limit_push.js')
-rw-r--r-- | jstests/sharding/limit_push.js | 69 |
1 files changed, 31 insertions, 38 deletions
diff --git a/jstests/sharding/limit_push.js b/jstests/sharding/limit_push.js index c77fee4c842..75ad271deb3 100644 --- a/jstests/sharding/limit_push.js +++ b/jstests/sharding/limit_push.js @@ -1,54 +1,47 @@ // This test is to ensure that limit() clauses are pushed down to the shards and evaluated // See: http://jira.mongodb.org/browse/SERVER-1896 -doTest = function( ) { +s = new ShardingTest( "limit_push", 2, 1, 1 ); - s = new ShardingTest( "limit_push", 2, 1, 1 ); +db = s.getDB( "test" ); - db = s.getDB( "test" ); +// Create some data +for (i=0; i < 100; i++) { db.limit_push.insert({ _id : i, x: i}); } +db.limit_push.ensureIndex( { x : 1 } ); +assert.eq( 100 , db.limit_push.find().length() , "Incorrect number of documents" ); - // Create some data - for (i=0; i < 100; i++) { db.limit_push.insert({ _id : i, x: i}); } - db.limit_push.ensureIndex( { x : 1 } ); - assert.eq( 100 , db.limit_push.find().length() , "Incorrect number of documents" ); +// Shard the collection +s.adminCommand( { enablesharding : "test" } ); +s.adminCommand( { shardcollection : "test.limit_push" , key : { x : 1 } } ); - // Shard the collection - s.adminCommand( { enablesharding : "test" } ); - s.adminCommand( { shardcollection : "test.limit_push" , key : { x : 1 } } ); +// Now split the and move the data between the shards +s.adminCommand( { split : "test.limit_push", middle : { x : 50 }} ); +s.adminCommand( { moveChunk: "test.limit_push", find : { x : 51}, to : "shard0000" }) - // Now split the and move the data between the shards - s.adminCommand( { split : "test.limit_push", middle : { x : 50 }} ); - s.adminCommand( { moveChunk: "test.limit_push", find : { x : 51}, to : "shard0000" }) +// Check that the chunck have split correctly +assert.eq( 2 , s.config.chunks.count() , "wrong number of chunks"); - // Check that the chunck have split correctly - assert.eq( 2 , s.config.chunks.count() , "wrong number of chunks"); +// The query is asking for the maximum value below a given value +// db.limit_push.find( { x : { $lt : 60} } ).sort( { x:-1} ).limit(1) +q = { x : { $lt : 60} }; - // The query is asking for the maximum value below a given value - // db.limit_push.find( { x : { $lt : 60} } ).sort( { x:-1} ).limit(1) - q = { x : { $lt : 60} }; +// Make sure the basic queries are correct +assert.eq( 60 , db.limit_push.find( q ).count() , "Did not find 60 documents" ); +//rs = db.limit_push.find( q ).sort( { x:-1} ).limit(1) +//assert.eq( rs , { _id : "1" , x : 59 } , "Did not find document with value 59" ); - // Make sure the basic queries are correct - assert.eq( 60 , db.limit_push.find( q ).count() , "Did not find 60 documents" ); - //rs = db.limit_push.find( q ).sort( { x:-1} ).limit(1) - //assert.eq( rs , { _id : "1" , x : 59 } , "Did not find document with value 59" ); +// Now make sure that the explain shos that each shard is returning a single document as indicated +// by the "n" element for each shard +exp = db.limit_push.find( q ).sort( { x:-1} ).limit(1).explain(); +printjson( exp ) - // Now make sure that the explain shos that each shard is returning a single document as indicated - // by the "n" element for each shard - exp = db.limit_push.find( q ).sort( { x:-1} ).limit(1).explain(); - - assert.eq("ParallelSort", exp.clusteredType, "Not a ParallelSort"); - - var k = 0; - for (var j in exp.shards) { - assert.eq( 1 , exp.shards[j][0].n, "'n' is not 1 from shard000" + k.toString()); - k++ - } - - s.stop(); +assert.eq("ParallelSort", exp.clusteredType, "Not a ParallelSort"); +var k = 0; +for (var j in exp.shards) { + assert.eq( 1 , exp.shards[j][0].n, "'n' is not 1 from shard000" + k.toString()); + k++ } -// Uncomment this when the bug is fixed -// doTest(); - +s.stop(); |