// static void Explain::generatePlannerInfo(CanonicalQuery* query, PlanStageStats* winnerStats, const vector<PlanStageStats*>& rejectedStats, BSONObjBuilder* out) { BSONObjBuilder plannerBob(out->subobjStart("queryPlanner"));; plannerBob.append("plannerVersion", QueryPlanner::kPlannerVersion); // In general we should have a canonical query, but sometimes we may avoid // creating a canonical query as an optimization (specifically, the update system // does not canonicalize for idhack updates). In these cases, 'query' is NULL. if (NULL != query) { BSONObjBuilder parsedQueryBob(plannerBob.subobjStart("parsedQuery")); query->root()->toBSON(&parsedQueryBob); parsedQueryBob.doneFast(); } BSONObjBuilder winningPlanBob(plannerBob.subobjStart("winningPlan")); explainStatsTree(*winnerStats, Explain::QUERY_PLANNER, &winningPlanBob); winningPlanBob.doneFast(); // Genenerate array of rejected plans. BSONArrayBuilder allPlansBob(plannerBob.subarrayStart("rejectedPlans")); for (size_t i = 0; i < rejectedStats.size(); i++) { BSONObjBuilder childBob(allPlansBob.subobjStart()); explainStatsTree(*rejectedStats[i], Explain::QUERY_PLANNER, &childBob); } allPlansBob.doneFast(); plannerBob.doneFast(); }
// static void Explain::generatePlannerInfo(CanonicalQuery* query, PlanStageStats* winnerStats, const vector<PlanStageStats*>& rejectedStats, BSONObjBuilder* out) { BSONObjBuilder plannerBob(out->subobjStart("queryPlanner"));; plannerBob.append("plannerVersion", QueryPlanner::kPlannerVersion); BSONObjBuilder parsedQueryBob(plannerBob.subobjStart("parsedQuery")); query->root()->toBSON(&parsedQueryBob); parsedQueryBob.doneFast(); BSONObjBuilder winningPlanBob(plannerBob.subobjStart("winningPlan")); explainStatsTree(*winnerStats, Explain::QUERY_PLANNER, &winningPlanBob); winningPlanBob.doneFast(); // Genenerate array of rejected plans. BSONArrayBuilder allPlansBob(plannerBob.subarrayStart("rejectedPlans")); for (size_t i = 0; i < rejectedStats.size(); i++) { BSONObjBuilder childBob(allPlansBob.subobjStart()); explainStatsTree(*rejectedStats[i], Explain::QUERY_PLANNER, &childBob); } allPlansBob.doneFast(); plannerBob.doneFast(); }
// static void Explain::explainCountEmptyQuery(BSONObjBuilder* out) { BSONObjBuilder plannerBob(out->subobjStart("queryPlanner")); plannerBob.append("plannerVersion", QueryPlanner::kPlannerVersion); plannerBob.append("winningPlan", "TRIVIAL_COUNT"); // Empty array of rejected plans. BSONArrayBuilder allPlansBob(plannerBob.subarrayStart("rejectedPlans")); allPlansBob.doneFast(); plannerBob.doneFast(); generateServerInfo(out); }