diff --git a/db/queryoptimizer.h b/db/queryoptimizer.h index b22049dee2e..e6318289f9c 100644 --- a/db/queryoptimizer.h +++ b/db/queryoptimizer.h @@ -106,6 +106,7 @@ namespace mongo { BSONObj indexKey() const; const char *ns() const { return fbs_.ns(); } BSONObj query() const { return fbs_.query(); } + const FieldBound &bound( const char *fieldName ) const { return fbs_.bound( fieldName ); } private: const FieldBoundSet &fbs_; const BSONObj &order_; diff --git a/dbtests/queryoptimizertests.cpp b/dbtests/queryoptimizertests.cpp index e23359ca68c..50d11012626 100644 --- a/dbtests/queryoptimizertests.cpp +++ b/dbtests/queryoptimizertests.cpp @@ -400,6 +400,29 @@ namespace QueryOptimizerTests { } }; + class Unhelpful : public Base { + public: + void run() { + QueryPlan p( FBS( BSON( "b" << 1 ) ), emptyObj, INDEX( "a" << 1 << "b" << 1 ) ); + ASSERT( p.keyMatch() ); + ASSERT( !p.bound( "a" ).nontrivial() ); + ASSERT( !p.unhelpful() ); + QueryPlan p2( FBS( BSON( "b" << 1 << "c" << 1 ) ), BSON( "a" << 1 ), INDEX( "a" << 1 << "b" << 1 ) ); + ASSERT( !p2.keyMatch() ); + ASSERT( !p2.scanAndOrderRequired() ); + ASSERT( !p2.bound( "a" ).nontrivial() ); + ASSERT( !p2.unhelpful() ); + QueryPlan p3( FBS( BSON( "b" << 1 << "c" << 1 ) ), emptyObj, INDEX( "b" << 1 ) ); + ASSERT( !p3.keyMatch() ); + ASSERT( p3.bound( "b" ).nontrivial() ); + ASSERT( !p3.unhelpful() ); + QueryPlan p4( FBS( BSON( "c" << 1 << "d" << 1 ) ), emptyObj, INDEX( "b" << 1 << "c" << 1 ) ); + ASSERT( !p4.keyMatch() ); + ASSERT( !p4.bound( "b" ).nontrivial() ); + ASSERT( p4.unhelpful() ); + } + }; + } // namespace QueryPlanTests namespace QueryPlanSetTests { @@ -671,6 +694,7 @@ namespace QueryOptimizerTests { add< QueryPlanTests::MoreOptimal >(); add< QueryPlanTests::KeyMatch >(); add< QueryPlanTests::ExactKeyQueryTypes >(); + add< QueryPlanTests::Unhelpful >(); add< QueryPlanSetTests::NoIndexes >(); add< QueryPlanSetTests::Optimal >(); add< QueryPlanSetTests::NoOptimal >();