Permalink
Browse files

SERVER-5354 Do not generate a field range constraint for an $atomic m…

…atch field.
  • Loading branch information...
1 parent 7c38913 commit 29e1815c4551f066a6d40c212941f2a9edccba20 @astaple astaple committed Sep 2, 2012
View
@@ -0,0 +1,14 @@
+// Use of an $atomic match expression does not affect choice of index. SERVER-5354
+
+t = db.jstests_queryoptimizerc;
+t.drop();
+
+function checkExplainResults( explain ) {
+ assert.eq( 'BtreeCursor a_1', explain.cursor ); // a:1 index chosen.
+ assert.eq( 1, explain.allPlans.length ); // Only one (optimal) plan is attempted.
+}
+
+t.ensureIndex( { a:1 } );
+
+checkExplainResults( t.find( { a:1 } ).explain( true ) );
+checkExplainResults( t.find( { a:1, $atomic:1 } ).explain( true ) );
@@ -995,6 +995,10 @@ namespace mongo {
if ( str::equals( matchFieldName, "$where" ) ) {
return;
}
+
+ if ( str::equals( matchFieldName, "$atomic" ) ) {
+ return;
+ }
}
bool equality =
@@ -3972,31 +3972,27 @@ namespace QueryOptimizerCursorTests {
void run() {
// Matcher validation with an empty collection.
_cli.remove( ns(), BSONObj() );
- // The historical behavior has been to generate a MsgAssertionException for the
- // multiple cursors case, but it should be a UserException.
- checkInvalidQueryAssertions<MsgAssertionException>();
+ checkInvalidQueryAssertions();
// Matcher validation with a missing collection.
_cli.dropCollection( ns() );
- checkInvalidQueryAssertions<UserException>();
+ checkInvalidQueryAssertions();
}
private:
- template<class MultipleCursorException>
static void checkInvalidQueryAssertions() {
Client::ReadContext ctx( ns() );
// An invalid query generaing a single query plan asserts.
BSONObj invalidQuery = fromjson( "{$and:[{$atomic:true}]}" );
- assertInvalidQueryAssertion<UserException>( invalidQuery );
+ assertInvalidQueryAssertion( invalidQuery );
// An invalid query generating multiple query plans asserts.
BSONObj invalidIdQuery = fromjson( "{_id:0,$and:[{$atomic:true}]}" );
- assertInvalidQueryAssertion<MultipleCursorException>( invalidIdQuery );
+ assertInvalidQueryAssertion( invalidIdQuery );
}
- template<class Exception>
static void assertInvalidQueryAssertion( const BSONObj &query ) {
ASSERT_THROWS( NamespaceDetailsTransient::getCursor( ns(), query, BSONObj() ),
- Exception );
+ UserException );
}
};
@@ -1269,6 +1269,18 @@ namespace QueryUtilTests {
}
};
+ /** No field range is generated for an $atomic field. SERVER-5354 */
+ class Atomic {
+ public:
+ void run() {
+ FieldRangeSet ranges( "", BSON( "a" << 1 << "$atomic" << 1 ), true, true );
+ // No range is computed for the '$atomic' field.
+ ASSERT( ranges.range( "$atomic" ).universal() );
+ // A standard equality range is computed for the 'a' field.
+ ASSERT( ranges.range( "a" ).equality() );
+ }
+ };
+
namespace ElemMatch {
/** Field ranges generated for the $elemMatch operator. */
@@ -2595,6 +2607,7 @@ namespace QueryUtilTests {
add<FieldRangeSetTests::MatchPossibleForIndex>();
add<FieldRangeSetTests::Subset>();
add<FieldRangeSetTests::Prefixed>();
+ add<FieldRangeSetTests::Atomic>();
add<FieldRangeSetTests::ElemMatch::Ranges>();
add<FieldRangeSetTests::ElemMatch::TopLevelElements>();
add<FieldRangeSetTests::ElemMatch::TopLevelNotElement>();

0 comments on commit 29e1815

Please sign in to comment.