Skip to content

Commit c4a61d6

Browse files
committed
avoid recording a bogus, unnecessary constraint on a $and field
1 parent 3f564bd commit c4a61d6

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/mongo/db/queryutil.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,8 @@ namespace mongo {
862862
while( j.more() ) {
863863
processQueryField( j.next(), optimize );
864864
}
865-
}
865+
}
866+
return;
866867
}
867868

868869
if ( strcmp( e.fieldName(), "$where" ) == 0 ) {

src/mongo/dbtests/queryutiltests.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,26 @@ namespace QueryUtilTests {
206206
BSONObj o1_, o2_;
207207
};
208208

209+
class And : public Base {
210+
public:
211+
And() : _o1( BSON( "-" << 0 ) ), _o2( BSON( "-" << 10 ) ) {}
212+
void run() {
213+
Base::run();
214+
const FieldRangeSet s( "ns", query(), true );
215+
// There should not be an index constraint recorded for the $and field.
216+
ASSERT( s.range( "$and" ).universal() );
217+
}
218+
private:
219+
virtual BSONObj query() {
220+
return BSON( "$and" <<
221+
BSON_ARRAY( BSON( "a" << GT << 0 ) << BSON( "a" << LTE << 10 ) ) );
222+
}
223+
virtual BSONElement lower() { return _o1.firstElement(); }
224+
virtual bool lowerInclusive() { return false; }
225+
virtual BSONElement upper() { return _o2.firstElement(); }
226+
BSONObj _o1, _o2;
227+
};
228+
209229
class Empty {
210230
public:
211231
void run() {
@@ -1079,6 +1099,7 @@ namespace QueryUtilTests {
10791099
add< FieldRangeTests::RegexObj >();
10801100
add< FieldRangeTests::UnhelpfulRegex >();
10811101
add< FieldRangeTests::In >();
1102+
add< FieldRangeTests::And >();
10821103
add< FieldRangeTests::Empty >();
10831104
add< FieldRangeTests::Equality >();
10841105
add< FieldRangeTests::SimplifiedQuery >();

0 commit comments

Comments
 (0)