Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix interpretation of non numberic index direction spec

  • Loading branch information...
commit 7d85516931e598348d61b86ec1a256ba388234ce 1 parent d4ede79
@astaple astaple authored
Showing with 14 additions and 1 deletion.
  1. +7 −1 db/queryoptimizer.cpp
  2. +7 −0 dbtests/queryoptimizertests.cpp
View
8 db/queryoptimizer.cpp
@@ -24,6 +24,12 @@
namespace mongo {
+ int elementDirection( const BSONElement &e ) {
+ if ( e.isNumber() )
+ return e.number();
+ return 1;
+ }
+
QueryPlan::QueryPlan( const FieldBoundSet &fbs, const BSONObj &order, const IndexDetails *index ) :
fbs_( fbs ),
order_( order ),
@@ -64,7 +70,7 @@ namespace mongo {
if ( !fbs.bound( ke.fieldName() ).equality() )
goto doneCheckOrder;
}
- int d = oe.number() == ke.number() ? 1 : -1;
+ int d = elementDirection( oe ) == elementDirection( ke ) ? 1 : -1;
if ( direction_ == 0 )
direction_ = d;
else if ( direction_ != d )
View
7 dbtests/queryoptimizertests.cpp
@@ -26,6 +26,10 @@
#include "dbtests.h"
+namespace mongo {
+ extern BSONObj id_obj;
+} // namespace mongo
+
namespace QueryOptimizerTests {
namespace FieldBoundTests {
@@ -335,6 +339,9 @@ namespace QueryOptimizerTests {
QueryPlan p2( FBS( BSONObj() ), BSON( "a" << 1 << "b" << -1 ), INDEX( "a" << 1 << "b" << 1 ) );
ASSERT( p2.scanAndOrderRequired() );
ASSERT_EQUALS( 0, p2.direction() );
+ QueryPlan p3( FBS( BSONObj() ), BSON( "_id" << 1 ), index( id_obj ) );
+ ASSERT( !p3.scanAndOrderRequired() );
+ ASSERT_EQUALS( 1, p3.direction() );
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.