summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2012-02-21 19:46:20 -0800
committerAaron <aaron@10gen.com>2012-02-24 22:49:16 -0800
commitb77af7efc90f6e8d70ae4304f3ca16f57c7a8c80 (patch)
tree098d330ec5d8783153c33e0a05b3667ae1f64858 /src
parentae93ce04ea63f1c998eee6870ac0348529cdd7ad (diff)
downloadmongo-b77af7efc90f6e8d70ae4304f3ca16f57c7a8c80.tar.gz
SERVER-4150 remove some obsolete query optimizer unit tests
Diffstat (limited to 'src')
-rw-r--r--src/mongo/dbtests/queryoptimizercursortests.cpp75
-rw-r--r--src/mongo/dbtests/queryoptimizertests.cpp226
2 files changed, 75 insertions, 226 deletions
diff --git a/src/mongo/dbtests/queryoptimizercursortests.cpp b/src/mongo/dbtests/queryoptimizercursortests.cpp
index 5d180c17704..8c1c43d5f32 100644
--- a/src/mongo/dbtests/queryoptimizercursortests.cpp
+++ b/src/mongo/dbtests/queryoptimizercursortests.cpp
@@ -2349,6 +2349,80 @@ namespace QueryOptimizerCursorTests {
}
};
+ class SaveGoodIndex : public Base {
+ public:
+ void run() {
+ _cli.ensureIndex( ns(), BSON( "a" << 1 ) );
+ _cli.ensureIndex( ns(), BSON( "b" << 1 ) );
+
+ dblock lk;
+ Client::Context ctx( ns() );
+
+ // No best plan - all must be tried.
+ nPlans( 3 );
+ runQuery();
+ // Best plan selected by query.
+ nPlans( 1 );
+ nPlans( 1 );
+ Helpers::ensureIndex( ns(), BSON( "c" << 1 ), false, "c_1" );
+ // Best plan cleared when new index added.
+ nPlans( 3 );
+ runQuery();
+ // Best plan selected by query.
+ nPlans( 1 );
+
+ {
+ DBDirectClient client;
+ for( int i = 0; i < 334; ++i ) {
+ client.insert( ns(), BSON( "i" << i ) );
+ client.update( ns(), QUERY( "i" << i ), BSON( "i" << i + 1 ) );
+ client.remove( ns(), BSON( "i" << i + 1 ) );
+ }
+ }
+ // Best plan cleared by ~1000 writes.
+ nPlans( 3 );
+
+ ParsedQuery parsedQuery( ns(), 0, 0, 0,
+ BSON( "$query" << BSON( "a" << 4 ) <<
+ "$hint" << BSON( "$natural" << 1 ) ), BSON( "b" << 1 ) );
+ shared_ptr<Cursor> cursor =
+ NamespaceDetailsTransient::getCursor( ns(), BSON( "a" << 4 ), BSONObj(),
+ QueryPlanSelectionPolicy::any(), 0, &parsedQuery );
+ while( cursor->advance() );
+ // No plan recorded when a hint is used.
+ nPlans( 3 );
+
+ ParsedQuery parsedQuery2( ns(), 0, 0, 0,
+ BSON( "$query" << BSON( "a" << 4 ) <<
+ "$orderby" << BSON( "b" << 1 << "c" << 1 ) ), BSONObj() );
+ shared_ptr<Cursor> cursor2 =
+ NamespaceDetailsTransient::getCursor( ns(), BSON( "a" << 4 ),
+ BSON( "b" << 1 << "c" << 1 ),
+ QueryPlanSelectionPolicy::any(), 0,
+ &parsedQuery2 );
+ while( cursor2->advance() );
+ // Plan recorded was for a different query pattern (different sort spec).
+ nPlans( 3 );
+
+ // Best plan still selected by query after all these other tests.
+ runQuery();
+ nPlans( 1 );
+ }
+ private:
+ void nPlans( int n ) {
+ auto_ptr< FieldRangeSetPair > frsp( new FieldRangeSetPair( ns(), BSON( "a" << 4 ) ) );
+ auto_ptr< FieldRangeSetPair > frspOrig( new FieldRangeSetPair( *frsp ) );
+ QueryPlanSet s( ns(), frsp, frspOrig, BSON( "a" << 4 ), shared_ptr<Projection>(),
+ BSON( "b" << 1 ) );
+ ASSERT_EQUALS( n, s.nPlans() );
+ }
+ void runQuery() {
+ shared_ptr<Cursor> cursor =
+ NamespaceDetailsTransient::getCursor( ns(), BSON( "a" << 4 ), BSON( "b" << 1 ) );
+ while( cursor->advance() );
+ }
+ };
+
namespace GetCursor {
class Base : public QueryOptimizerCursorTests::Base {
@@ -3363,6 +3437,7 @@ namespace QueryOptimizerCursorTests {
add<NoTakeoverByOutOfOrderPlan>();
add<CoveredIndex>();
add<CoveredIndexTakeover>();
+ add<SaveGoodIndex>();
add<GetCursor::NoConstraints>();
add<GetCursor::SimpleId>();
add<GetCursor::OptimalIndex>();
diff --git a/src/mongo/dbtests/queryoptimizertests.cpp b/src/mongo/dbtests/queryoptimizertests.cpp
index cc63cc7b89b..035b66a2d82 100644
--- a/src/mongo/dbtests/queryoptimizertests.cpp
+++ b/src/mongo/dbtests/queryoptimizertests.cpp
@@ -728,228 +728,6 @@ namespace QueryOptimizerTests {
}
};
- class SingleException : public Base {
- public:
- void run() {
- Helpers::ensureIndex( ns(), BSON( "a" << 1 ), false, "a_1" );
- Helpers::ensureIndex( ns(), BSON( "b" << 1 ), false, "b_1" );
- auto_ptr< FieldRangeSetPair > frsp( new FieldRangeSetPair( ns(), BSON( "a" << 4 ) ) );
- auto_ptr< FieldRangeSetPair > frspOrig( new FieldRangeSetPair( *frsp ) );
- QueryPlanSet s( ns(), frsp, frspOrig, BSON( "a" << 4 ), shared_ptr<Projection>(),
- BSON( "b" << 1 ) );
- ASSERT_EQUALS( 3, s.nPlans() );
- bool threw = false;
- auto_ptr< TestOp > t( new TestOp( true, threw ) );
- boost::shared_ptr< TestOp > done = s.runOp( *t );
- ASSERT( threw );
- ASSERT( done->complete() );
- ASSERT( done->exception().empty() );
- ASSERT( !done->error() );
- }
- private:
- class TestOp : public QueryOp {
- public:
- TestOp( bool iThrow, bool &threw ) : iThrow_( iThrow ), threw_( threw ), i_(), youThrow_( false ) {}
- virtual void _init() {}
- virtual void next() {
- if ( iThrow_ )
- threw_ = true;
- massert( 10408 , "throw", !iThrow_ );
- if ( ++i_ > 10 )
- setComplete();
- }
- virtual QueryOp *_createChild() const {
- QueryOp *op = new TestOp( youThrow_, threw_ );
- youThrow_ = !youThrow_;
- return op;
- }
- virtual bool mayRecordPlan() const { return true; }
- virtual long long nscanned() { return 0; }
- private:
- bool iThrow_;
- bool &threw_;
- int i_;
- mutable bool youThrow_;
- };
- };
-
- class AllException : public Base {
- public:
- void run() {
- Helpers::ensureIndex( ns(), BSON( "a" << 1 ), false, "a_1" );
- Helpers::ensureIndex( ns(), BSON( "b" << 1 ), false, "b_1" );
- auto_ptr< FieldRangeSetPair > frsp( new FieldRangeSetPair( ns(), BSON( "a" << 4 ) ) );
- auto_ptr< FieldRangeSetPair > frspOrig( new FieldRangeSetPair( *frsp ) );
- QueryPlanSet s( ns(), frsp, frspOrig, BSON( "a" << 4 ), shared_ptr<Projection>(),
- BSON( "b" << 1 ) );
- ASSERT_EQUALS( 3, s.nPlans() );
- auto_ptr< TestOp > t( new TestOp() );
- boost::shared_ptr< TestOp > done = s.runOp( *t );
- ASSERT( !done->complete() );
- ASSERT_EQUALS( "throw", done->exception().msg );
- ASSERT( done->error() );
- }
- private:
- class TestOp : public QueryOp {
- public:
- virtual void _init() {}
- virtual void next() {
- massert( 10409 , "throw", false );
- }
- virtual QueryOp *_createChild() const {
- return new TestOp();
- }
- virtual bool mayRecordPlan() const { return true; }
- virtual long long nscanned() { return 0; }
- };
- };
-
- class SaveGoodIndex : public Base {
- public:
- void run() {
- Helpers::ensureIndex( ns(), BSON( "a" << 1 ), false, "a_1" );
- Helpers::ensureIndex( ns(), BSON( "b" << 1 ), false, "b_1" );
- // No best plan - all must be tried.
- nPlans( 3 );
- runQuery();
- // Best plan selected by query.
- nPlans( 1 );
- nPlans( 1 );
- Helpers::ensureIndex( ns(), BSON( "c" << 1 ), false, "c_1" );
- // Best plan cleared when new index added.
- nPlans( 3 );
- runQuery();
- // Best plan selected by query.
- nPlans( 1 );
-
- {
- DBDirectClient client;
- for( int i = 0; i < 334; ++i ) {
- client.insert( ns(), BSON( "i" << i ) );
- client.update( ns(), QUERY( "i" << i ), BSON( "i" << i + 1 ) );
- client.remove( ns(), BSON( "i" << i + 1 ) );
- }
- }
- // Best plan cleared by ~1000 writes.
- nPlans( 3 );
-
- auto_ptr< FieldRangeSetPair > frsp( new FieldRangeSetPair( ns(), BSON( "a" << 4 ) ) );
- auto_ptr< FieldRangeSetPair > frspOrig( new FieldRangeSetPair( *frsp ) );
- QueryPlanSet s( ns(), frsp, frspOrig, BSON( "a" << 4 ), shared_ptr<Projection>(),
- BSON( "b" << 1 ) );
- NoRecordTestOp original;
- s.runOp( original );
- // NoRecordTestOp doesn't record a best plan (test cases where mayRecordPlan() is false).
- nPlans( 3 );
-
- BSONObj hint = fromjson( "{hint:{$natural:1}}" );
- auto_ptr< FieldRangeSetPair > frsp2( new FieldRangeSetPair( ns(), BSON( "a" << 4 ) ) );
- auto_ptr< FieldRangeSetPair > frspOrig2( new FieldRangeSetPair( *frsp2 ) );
- QueryPlanSet s2( ns(), frsp2, frspOrig2, BSON( "a" << 4 ), shared_ptr<Projection>(),
- BSON( "b" << 1 ), true,
- hint );
- TestOp newOriginal;
- s2.runOp( newOriginal );
- // No plan recorded when a hint is used.
- nPlans( 3 );
-
- auto_ptr< FieldRangeSetPair > frsp3( new FieldRangeSetPair( ns(), BSON( "a" << 4 ), true ) );
- auto_ptr< FieldRangeSetPair > frspOrig3( new FieldRangeSetPair( *frsp3 ) );
- QueryPlanSet s3( ns(), frsp3, frspOrig3, BSON( "a" << 4 ), shared_ptr<Projection>(),
- BSON( "b" << 1 << "c" << 1 ) );
- TestOp newerOriginal;
- s3.runOp( newerOriginal );
- // Plan recorded was for a different query pattern (different sort spec).
- nPlans( 3 );
-
- // Best plan still selected by query after all these other tests.
- runQuery();
- nPlans( 1 );
- }
- private:
- void nPlans( int n ) {
- auto_ptr< FieldRangeSetPair > frsp( new FieldRangeSetPair( ns(), BSON( "a" << 4 ) ) );
- auto_ptr< FieldRangeSetPair > frspOrig( new FieldRangeSetPair( *frsp ) );
- QueryPlanSet s( ns(), frsp, frspOrig, BSON( "a" << 4 ), shared_ptr<Projection>(),
- BSON( "b" << 1 ) );
- ASSERT_EQUALS( n, s.nPlans() );
- }
- void runQuery() {
- auto_ptr< FieldRangeSetPair > frsp( new FieldRangeSetPair( ns(), BSON( "a" << 4 ) ) );
- auto_ptr< FieldRangeSetPair > frspOrig( new FieldRangeSetPair( *frsp ) );
- QueryPlanSet s( ns(), frsp, frspOrig, BSON( "a" << 4 ), shared_ptr<Projection>(),
- BSON( "b" << 1 ) );
- TestOp original;
- s.runOp( original );
- }
- class TestOp : public QueryOp {
- public:
- virtual void _init() {}
- virtual void next() {
- setComplete();
- }
- virtual QueryOp *_createChild() const {
- return new TestOp();
- }
- virtual bool mayRecordPlan() const { return true; }
- virtual long long nscanned() { return 0; }
- };
- class NoRecordTestOp : public TestOp {
- virtual bool mayRecordPlan() const { return false; }
- virtual QueryOp *_createChild() const { return new NoRecordTestOp(); }
- };
- };
-
- class TryAllPlansOnErr : public Base {
- public:
- void run() {
- Helpers::ensureIndex( ns(), BSON( "a" << 1 ), false, "a_1" );
-
- auto_ptr< FieldRangeSetPair > frsp( new FieldRangeSetPair( ns(), BSON( "a" << 4 ) ) );
- auto_ptr< FieldRangeSetPair > frspOrig( new FieldRangeSetPair( *frsp ) );
- QueryPlanSet s( ns(), frsp, frspOrig, BSON( "a" << 4 ), shared_ptr<Projection>(),
- BSON( "b" << 1 ) );
- ScanOnlyTestOp op;
- s.runOp( op );
- pair< BSONObj, long long > best = QueryUtilIndexed::bestIndexForPatterns( s.frsp(), BSON( "b" << 1 ) );
- ASSERT( fromjson( "{$natural:1}" ).woCompare( best.first ) == 0 );
- ASSERT_EQUALS( 1, best.second );
-
- auto_ptr< FieldRangeSetPair > frsp2( new FieldRangeSetPair( ns(), BSON( "a" << 4 ) ) );
- auto_ptr< FieldRangeSetPair > frspOrig2( new FieldRangeSetPair( *frsp2 ) );
- QueryPlanSet s2( ns(), frsp2, frspOrig2, BSON( "a" << 4 ), shared_ptr<Projection>(),
- BSON( "b" << 1 ) );
- TestOp op2;
- ASSERT( s2.runOp( op2 )->complete() );
- }
- private:
- class TestOp : public QueryOp {
- public:
- TestOp() {}
- virtual void _init() {}
- virtual void next() {
- if ( qp().indexKey().firstElementFieldName() == string( "$natural" ) )
- massert( 10410 , "throw", false );
- setComplete();
- }
- virtual QueryOp *_createChild() const {
- return new TestOp();
- }
- virtual bool mayRecordPlan() const { return true; }
- virtual long long nscanned() { return 1; }
- };
- class ScanOnlyTestOp : public TestOp {
- virtual void next() {
- if ( qp().indexKey().firstElement().fieldName() == string( "$natural" ) )
- setComplete();
- massert( 10411 , "throw", false );
- }
- virtual QueryOp *_createChild() const {
- return new ScanOnlyTestOp();
- }
- };
- };
-
class FindOne : public Base {
public:
void run() {
@@ -1239,10 +1017,6 @@ namespace QueryOptimizerTests {
add<QueryPlanSetTests::Count>();
add<QueryPlanSetTests::QueryMissingNs>();
add<QueryPlanSetTests::UnhelpfulIndex>();
- add<QueryPlanSetTests::SingleException>();
- add<QueryPlanSetTests::AllException>();
- add<QueryPlanSetTests::SaveGoodIndex>();
- add<QueryPlanSetTests::TryAllPlansOnErr>();
add<QueryPlanSetTests::FindOne>();
add<QueryPlanSetTests::Delete>();
add<QueryPlanSetTests::DeleteOneScan>();