Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

SERVER-5067 Ensure MatchDetails requests are forwarded by the QueryOp…

…timizerCursor.
  • Loading branch information...
commit 708047ab122004fdaa6618131d0f24d6d810fb6d 1 parent aa69814
@astaple astaple authored
View
11 src/mongo/db/queryoptimizercursorimpl.cpp
@@ -183,19 +183,20 @@ namespace mongo {
}
MatchDetails myDetails;
- bool wantDetails = details || _explainPlanInfo;
+ if ( !details && _explainPlanInfo ) {
+ details = &myDetails;
+ }
- bool match = matcher( _c.get() )->matchesCurrent( _c.get(),
- wantDetails ? &myDetails : 0 );
+ bool match = matcher( _c.get() )->matchesCurrent( _c.get(), details );
// Cache the match, so we can count it in mayAdvance().
bool newMatch = _matchCounter.setMatch( match );
if ( _explainPlanInfo ) {
bool countableMatch = newMatch && _matchCounter.wouldCountMatch( _c->currLoc() );
_explainPlanInfo->noteIterate( countableMatch,
- countableMatch || myDetails.loadedObject(), *_c );
+ countableMatch || details->loadedObject(),
+ *_c );
}
- if ( details ) *details = myDetails;
return match;
}
View
18 src/mongo/dbtests/queryoptimizercursortests.cpp
@@ -3289,6 +3289,23 @@ namespace QueryOptimizerCursorTests {
ASSERT_EQUALS( 200, nextA );
}
};
+
+ /** Check that an elemMatchKey can be retrieved from MatchDetails using a qo cursor. */
+ class ElemMatchKey : public Base {
+ public:
+ void run() {
+ _cli.ensureIndex( ns(), BSON( "a.b" << 1 ) );
+ _cli.insert( ns(), fromjson( "{ a:[ { b:1 } ] }" ) );
+
+ Client::ReadContext ctx( ns() );
+ setQueryOptimizerCursor( BSON( "a.b" << 1 ) );
+ MatchDetails details;
+ details.requestElemMatchKey();
+ ASSERT( c()->currentMatches( &details ) );
+ // The '0' entry of the 'a' array is matched.
+ ASSERT_EQUALS( string( "0" ), details.elemMatchKey() );
+ }
+ };
namespace GetCursor {
@@ -4453,6 +4470,7 @@ namespace QueryOptimizerCursorTests {
add<TakeoverOrRangeElimination>();
add<TakeoverOrDedups>();
add<TakeoverOrderedPlanDupsOutOfOrderPlan>();
+ add<ElemMatchKey>();
add<GetCursor::NoConstraints>();
add<GetCursor::SimpleId>();
add<GetCursor::OptimalIndex>();
Please sign in to comment.
Something went wrong with that request. Please try again.