2014-08-27 15:36:08 -04:00
|
|
|
// Check explain results for a plan that uses an index to obtain the requested sort order.
|
2012-02-14 09:30:08 -08:00
|
|
|
|
|
|
|
|
t = db.jstests_explain5;
|
|
|
|
|
t.drop();
|
|
|
|
|
|
2014-08-27 15:36:08 -04:00
|
|
|
t.ensureIndex( { a:1 } );
|
|
|
|
|
t.ensureIndex( { b:1 } );
|
2012-02-14 09:30:08 -08:00
|
|
|
|
2014-08-27 15:36:08 -04:00
|
|
|
for( i = 0; i < 1000; ++i ) {
|
|
|
|
|
t.save( { a:i, b:i%3 } );
|
2012-02-14 09:30:08 -08:00
|
|
|
}
|
|
|
|
|
|
2014-08-27 15:36:08 -04:00
|
|
|
// Query with an initial set of documents.
|
2014-10-07 18:23:21 -04:00
|
|
|
var explain1 = t.find( { a:{ $gte:0 }, b:2 } ).sort( { a:1 } )
|
|
|
|
|
.hint( { a:1 } )
|
|
|
|
|
.explain("executionStats");
|
2014-08-27 15:36:08 -04:00
|
|
|
printjson(explain1);
|
|
|
|
|
var stats1 = explain1.executionStats;
|
|
|
|
|
assert.eq( 333, stats1.nReturned, 'wrong nReturned for explain1' );
|
|
|
|
|
assert.eq( 1000, stats1.totalKeysExamined, 'wrong totalKeysExamined for explain1' );
|
2012-03-13 18:26:59 -07:00
|
|
|
|
2014-08-27 15:36:08 -04:00
|
|
|
for( i = 1000; i < 2000; ++i ) {
|
|
|
|
|
t.save( { a:i, b:i%3 } );
|
2014-02-18 15:32:01 -05:00
|
|
|
}
|
2014-08-27 15:36:08 -04:00
|
|
|
|
|
|
|
|
// Query with some additional documents.
|
2014-10-07 18:23:21 -04:00
|
|
|
var explain2 = t.find( { a:{ $gte:0 }, b:2 } ).sort( { a:1 } )
|
|
|
|
|
.hint ( { a:1 } )
|
|
|
|
|
.explain("executionStats");
|
2014-08-27 15:36:08 -04:00
|
|
|
printjson(explain2);
|
|
|
|
|
var stats2 = explain2.executionStats;
|
|
|
|
|
assert.eq( 666, stats2.nReturned, 'wrong nReturned for explain2' );
|
|
|
|
|
assert.eq( 2000, stats2.totalKeysExamined, 'wrong totalKeysExamined for explain2' );
|