Skip to content

Commit

Permalink
SERVER-10448 migrate code out of explain_plan.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
dstorch committed Jul 31, 2014
1 parent 0028a33 commit b494ade
Show file tree
Hide file tree
Showing 14 changed files with 266 additions and 437 deletions.
4 changes: 2 additions & 2 deletions jstests/core/explain1.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ assert.eq( 49 , t.find(q).batchSize(20).explain().n , "J" );
// display index bounds

var explainGt = t.find({x: {$gt: 5}}).explain(true);
var boundsVerboseGt = explainGt.stats.children[0].boundsVerbose;
var boundsVerboseGt = explainGt.stats.inputStage.indexBounds;

print('explain stats for $gt = ' + tojson(explainGt.stats));

var explainGte = t.find({x: {$gte: 5}}).explain(true);
var boundsVerboseGte = explainGte.stats.children[0].boundsVerbose;
var boundsVerboseGte = explainGte.stats.inputStage.indexBounds;

print('explain stats for $gte = ' + tojson(explainGte.stats));

Expand Down
2 changes: 1 addition & 1 deletion jstests/core/fts_explain.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ assert.writeOK(res);

var explain = coll.find({$text:{$search: "\"a\" -b -\"c\""}}).explain(true);
assert.eq(explain.cursor, "TextCursor");
assert.eq(explain.stats.type, "TEXT");
assert.eq(explain.stats.stage, "TEXT");
assert.eq(explain.stats.parsedTextQuery.terms, ["a"]);
assert.eq(explain.stats.parsedTextQuery.negatedTerms, ["b"]);
assert.eq(explain.stats.parsedTextQuery.phrases, ["a"]);
Expand Down
2 changes: 1 addition & 1 deletion jstests/core/plan_cache_list_plans.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ for (var i = 0; i < plans.length; i++) {
'plans not sorted by score in descending order. ' +
'plan ' + i + ' has a score that is greater than that of the previous plan');
}
assert(plans[i].reason.stats.hasOwnProperty('type'), 'no stats inserted for plan ' + i);
assert(plans[i].reason.stats.hasOwnProperty('stage'), 'no stats inserted for plan ' + i);
}

4 changes: 2 additions & 2 deletions jstests/core/profile4.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ try {
t.ensureIndex( {a:1} );
t.find( {a:1} ).itcount();
o = lastOp();
assert.eq( "FETCH", o.execStats.type, tojson( o.execStats ) );
assert.eq( "IXSCAN", o.execStats.children[0].type, tojson( o.execStats ) );
assert.eq( "FETCH", o.execStats.stage, tojson( o.execStats ) );
assert.eq( "IXSCAN", o.execStats.inputStage.stage, tojson( o.execStats ) );

// For queries with a lot of stats data, the execution stats in the profile
// is replaced by the plan summary.
Expand Down
3 changes: 3 additions & 0 deletions src/mongo/db/commands/explain_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ namespace mongo {
else if (mongoutils::str::equals(verbStr, "allPlansExecution")) {
verbosity = Explain::EXEC_ALL_PLANS;
}
else if (mongoutils::str::equals(verbStr, "full")) {
verbosity = Explain::FULL;
}
else if (!mongoutils::str::equals(verbStr, "queryPlanner")) {
errmsg = "verbosity string must be one of "
"{'queryPlanner', 'executionStats', 'allPlansExecution'}";
Expand Down
4 changes: 2 additions & 2 deletions src/mongo/db/commands/plan_cache_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/commands/plan_cache_commands.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/db/query/explain_plan.h"
#include "mongo/db/query/explain.h"
#include "mongo/db/query/plan_ranker.h"
#include "mongo/util/log.h"

Expand Down Expand Up @@ -406,7 +406,7 @@ namespace mongo {
BSONObjBuilder statsBob(reasonBob.subobjStart("stats"));
PlanStageStats* stats = entry->decision->stats.vector()[i];
if (stats) {
statsToBSON(*stats, &statsBob);
Explain::statsToBSON(*stats, &statsBob);
}
statsBob.doneFast();
reasonBob.doneFast();
Expand Down
11 changes: 6 additions & 5 deletions src/mongo/db/exec/multi_plan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/database.h"
#include "mongo/db/client.h"
#include "mongo/db/query/explain_plan.h"
#include "mongo/db/query/explain.h"
#include "mongo/db/query/plan_cache.h"
#include "mongo/db/query/plan_ranker.h"
#include "mongo/db/query/qlog.h"
Expand Down Expand Up @@ -204,7 +204,7 @@ namespace mongo {
QuerySolution* bestSolution = bestCandidate.solution;

QLOG() << "Winning solution:\n" << bestSolution->toString() << endl;
LOG(2) << "Winning plan: " << getPlanSummary(*bestSolution);
LOG(2) << "Winning plan: " << Explain::getPlanSummary(bestCandidate.root);

_backupPlanIdx = kNoSuchPlan;
if (bestSolution->hasBlockingStage && (0 == alreadyProduced.size())) {
Expand Down Expand Up @@ -232,10 +232,10 @@ namespace mongo {
<< " " << _query->toStringShort()
<< " winner score: " << ranking->scores[0]
<< " winner summary: "
<< getPlanSummary(*_candidates[winnerIdx].solution)
<< Explain::getPlanSummary(_candidates[winnerIdx].root)
<< " runner-up score: " << ranking->scores[1]
<< " runner-up summary: "
<< getPlanSummary(*_candidates[runnerUpIdx].solution);
<< Explain::getPlanSummary(_candidates[runnerUpIdx].root);

// There could be more than a 2-way tie, so log the stats for the remaining plans
// involved in the tie.
Expand All @@ -251,7 +251,8 @@ namespace mongo {
<< " ns: " << _collection->ns()
<< " " << _query->toStringShort()
<< " score: " << ranking->scores[i]
<< " summary: " << getPlanSummary(*_candidates[planIdx].solution);
<< " summary: "
<< Explain::getPlanSummary(_candidates[planIdx].root);
}
}

Expand Down
Loading

0 comments on commit b494ade

Please sign in to comment.