Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Simplify generation of summary information for old explain plan.

  • Loading branch information...
commit a9930f559f2fa641ccfc8de3acc0f3a67e35f34c 1 parent c8ac89f
@astaple astaple authored
View
6 src/mongo/db/ops/query.cpp
@@ -915,11 +915,7 @@ namespace mongo {
BSONObj oldPlan;
if ( explain && ! pq.hasIndexSpecifier() ) {
MultiPlanScanner mps( ns, query, order );
- if ( mps.usingCachedPlan() ) {
- oldPlan =
- mps.oldExplain().firstElement().embeddedObject()
- .firstElement().embeddedObject().getOwned();
- }
+ oldPlan = mps.cachedPlanExplainSummary();
}
// In some cases the query may be retried if there is an in memory sort size assertion.
View
24 src/mongo/db/queryoptimizer.cpp
@@ -688,20 +688,6 @@ namespace mongo {
_mayRecordPlan = true;
}
- BSONObj QueryPlanSet::explain() const {
- vector<BSONObj> arr;
- for( PlanSet::const_iterator i = _plans.begin(); i != _plans.end(); ++i ) {
- shared_ptr<Cursor> c = (*i)->newCursor();
- BSONObjBuilder explain;
- explain.append( "cursor", c->toString() );
- explain.append( "indexBounds", c->prettyIndexBounds() );
- arr.push_back( explain.obj() );
- }
- BSONObjBuilder b;
- b.append( "allPlans", arr );
- return b.obj();
- }
-
QueryPlanSet::QueryPlanPtr QueryPlanSet::getBestGuess() const {
verify( _plans.size() );
if ( _plans[ 0 ]->scanAndOrderRequired() ) {
@@ -1159,6 +1145,16 @@ namespace mongo {
return QueryUtilIndexed::uselessOr( *_org, nsd, -1 );
}
+ BSONObj MultiPlanScanner::cachedPlanExplainSummary() const {
+ if ( _or || !_currentQps->usingCachedPlan() ) {
+ return BSONObj();
+ }
+ QueryPlanSet::QueryPlanPtr plan = _currentQps->firstPlan();
+ shared_ptr<Cursor> cursor = plan->newCursor();
+ return BSON( "cursor" << cursor->toString()
+ << "indexBounds" << cursor->prettyIndexBounds() );
+ }
+
void MultiPlanScanner::clearIndexesForPatterns() const {
QueryUtilIndexed::clearIndexesForPatterns( _currentQps->frsp(), _currentQps->order() );
}
View
9 src/mongo/db/queryoptimizer.h
@@ -318,8 +318,6 @@ namespace mongo {
QueryPlanPtr firstPlan() const { return _plans[ 0 ]; }
- /** @return metadata about cursors and index bounds for all plans, suitable for explain output. */
- BSONObj explain() const;
/** @return true iff a plan is selected based on previous success of this plan. */
bool usingCachedPlan() const { return _usingCachedPlan; }
/** @return a single plan that may work well for the specified query. */
@@ -488,8 +486,11 @@ namespace mongo {
bool mayRunMore() const {
return _or ? ( !_tableScanned && !_org->orRangesExhausted() ) : _i == 0;
}
- /** @return non-$or version of explain output. */
- BSONObj oldExplain() const { assertNotOr(); return _currentQps->explain(); }
+ /**
+ * @return plan information if there is a cached plan for a non $or query, otherwise an
+ * empty object.
+ */
+ BSONObj cachedPlanExplainSummary() const;
/** @return true iff this is not a $or query and a plan is selected based on previous success of this plan. */
bool usingCachedPlan() const { return !_or && _currentQps->usingCachedPlan(); }
bool hasMultiKey() const { return _currentQps->hasMultiKey(); }
Please sign in to comment.
Something went wrong with that request. Please try again.