diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/curop.cpp | 14 | ||||
-rw-r--r-- | src/mongo/db/curop.h | 2 | ||||
-rw-r--r-- | src/mongo/db/exec/cached_plan.cpp | 17 | ||||
-rw-r--r-- | src/mongo/db/exec/cached_plan.h | 2 | ||||
-rw-r--r-- | src/mongo/db/exec/plan_stats.h | 4 | ||||
-rw-r--r-- | src/mongo/db/query/explain.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/query/plan_summary_stats.h | 2 | ||||
-rw-r--r-- | src/mongo/db/sorter/sorter.cpp | 6 |
8 files changed, 32 insertions, 17 deletions
diff --git a/src/mongo/db/curop.cpp b/src/mongo/db/curop.cpp index 2148d07cfc0..3e955602948 100644 --- a/src/mongo/db/curop.cpp +++ b/src/mongo/db/curop.cpp @@ -725,7 +725,11 @@ string OpDebug::report(OperationContext* opCtx, const SingleThreadedLockStats* l OPDEBUG_TOSTRING_HELP_BOOL(hasSortStage); OPDEBUG_TOSTRING_HELP_BOOL(usedDisk); OPDEBUG_TOSTRING_HELP_BOOL(fromMultiPlanner); - OPDEBUG_TOSTRING_HELP_BOOL(replanned); + if (replanReason) { + bool replanned = true; + OPDEBUG_TOSTRING_HELP_BOOL(replanned); + s << " replanReason:\"" << str::escape(redact(*replanReason)) << "\""; + } OPDEBUG_TOSTRING_HELP_OPTIONAL("nMatched", additiveMetrics.nMatched); OPDEBUG_TOSTRING_HELP_OPTIONAL("nModified", additiveMetrics.nModified); OPDEBUG_TOSTRING_HELP_OPTIONAL("ninserted", additiveMetrics.ninserted); @@ -840,7 +844,11 @@ void OpDebug::append(OperationContext* opCtx, OPDEBUG_APPEND_BOOL(hasSortStage); OPDEBUG_APPEND_BOOL(usedDisk); OPDEBUG_APPEND_BOOL(fromMultiPlanner); - OPDEBUG_APPEND_BOOL(replanned); + if (replanReason) { + bool replanned = true; + OPDEBUG_APPEND_BOOL(replanned); + b.append("replanReason", *replanReason); + } OPDEBUG_APPEND_OPTIONAL("nMatched", additiveMetrics.nMatched); OPDEBUG_APPEND_OPTIONAL("nModified", additiveMetrics.nModified); OPDEBUG_APPEND_OPTIONAL("ninserted", additiveMetrics.ninserted); @@ -921,7 +929,7 @@ void OpDebug::setPlanSummaryMetrics(const PlanSummaryStats& planSummaryStats) { hasSortStage = planSummaryStats.hasSortStage; usedDisk = planSummaryStats.usedDisk; fromMultiPlanner = planSummaryStats.fromMultiPlanner; - replanned = planSummaryStats.replanned; + replanReason = planSummaryStats.replanReason; } BSONObj OpDebug::makeFlowControlObject(FlowControlTicketholder::CurOp stats) const { diff --git a/src/mongo/db/curop.h b/src/mongo/db/curop.h index a37700eedbf..3090b8c8124 100644 --- a/src/mongo/db/curop.h +++ b/src/mongo/db/curop.h @@ -202,7 +202,7 @@ public: bool fromMultiPlanner{false}; // True if a replan was triggered during the execution of this operation. - bool replanned{false}; + std::optional<std::string> replanReason; bool upsert{false}; // true if the update actually did an insert bool cursorExhausted{ diff --git a/src/mongo/db/exec/cached_plan.cpp b/src/mongo/db/exec/cached_plan.cpp index 9738936f4b7..7f35e28a63d 100644 --- a/src/mongo/db/exec/cached_plan.cpp +++ b/src/mongo/db/exec/cached_plan.cpp @@ -147,7 +147,10 @@ Status CachedPlanStage::pickBestPlan(PlanYieldPolicy* yieldPolicy) { << " status: " << redact(statusObj); const bool shouldCache = false; - return replan(yieldPolicy, shouldCache); + return replan(yieldPolicy, + shouldCache, + str::stream() << "cached plan returned: " + << WorkingSetCommon::toStatusString(statusObj)); } else { invariant(PlanStage::NEED_TIME == state); } @@ -162,7 +165,13 @@ Status CachedPlanStage::pickBestPlan(PlanYieldPolicy* yieldPolicy) { << " plan summary before replan: " << Explain::getPlanSummary(child().get()); const bool shouldCache = true; - return replan(yieldPolicy, shouldCache); + return replan( + yieldPolicy, + shouldCache, + str::stream() + << "cached plan was less efficient than expected: expected trial execution to take " + << _decisionWorks << " works but it took at least " << maxWorksBeforeReplan + << " works"); } Status CachedPlanStage::tryYield(PlanYieldPolicy* yieldPolicy) { @@ -179,7 +188,7 @@ Status CachedPlanStage::tryYield(PlanYieldPolicy* yieldPolicy) { return Status::OK(); } -Status CachedPlanStage::replan(PlanYieldPolicy* yieldPolicy, bool shouldCache) { +Status CachedPlanStage::replan(PlanYieldPolicy* yieldPolicy, bool shouldCache, std::string reason) { // We're going to start over with a new plan. Clear out info from our old plan. { std::queue<WorkingSetID> emptyQueue; @@ -188,7 +197,7 @@ Status CachedPlanStage::replan(PlanYieldPolicy* yieldPolicy, bool shouldCache) { _ws->clear(); _children.clear(); - _specificStats.replanned = true; + _specificStats.replanReason = std::move(reason); if (shouldCache) { // Deactivate the current cache entry. diff --git a/src/mongo/db/exec/cached_plan.h b/src/mongo/db/exec/cached_plan.h index bc7b1bc50bb..8a5fe5871d3 100644 --- a/src/mongo/db/exec/cached_plan.h +++ b/src/mongo/db/exec/cached_plan.h @@ -106,7 +106,7 @@ private: * * We only modify the plan cache if 'shouldCache' is true. */ - Status replan(PlanYieldPolicy* yieldPolicy, bool shouldCache); + Status replan(PlanYieldPolicy* yieldPolicy, bool shouldCache, std::string reason); /** * May yield during the cached plan stage's trial period or replanning phases. diff --git a/src/mongo/db/exec/plan_stats.h b/src/mongo/db/exec/plan_stats.h index e08f366f85e..ea75f673b81 100644 --- a/src/mongo/db/exec/plan_stats.h +++ b/src/mongo/db/exec/plan_stats.h @@ -201,7 +201,7 @@ struct AndSortedStats : public SpecificStats { }; struct CachedPlanStats : public SpecificStats { - CachedPlanStats() : replanned(false) {} + CachedPlanStats() = default; SpecificStats* clone() const final { return new CachedPlanStats(*this); @@ -211,7 +211,7 @@ struct CachedPlanStats : public SpecificStats { return sizeof(*this); } - bool replanned; + std::optional<std::string> replanReason; }; struct CollectionScanStats : public SpecificStats { diff --git a/src/mongo/db/query/explain.cpp b/src/mongo/db/query/explain.cpp index 9fa426ad53b..c73a0e41bd3 100644 --- a/src/mongo/db/query/explain.cpp +++ b/src/mongo/db/query/explain.cpp @@ -1016,7 +1016,7 @@ void Explain::getSummaryStats(const PlanExecutor& exec, PlanSummaryStats* statsO const CachedPlanStage* cachedPlan = static_cast<const CachedPlanStage*>(stages[i]); const CachedPlanStats* cachedStats = static_cast<const CachedPlanStats*>(cachedPlan->getSpecificStats()); - statsOut->replanned = cachedStats->replanned; + statsOut->replanReason = cachedStats->replanReason; } else if (STAGE_MULTI_PLAN == stages[i]->stageType()) { statsOut->fromMultiPlanner = true; } else if (STAGE_COLLSCAN == stages[i]->stageType()) { diff --git a/src/mongo/db/query/plan_summary_stats.h b/src/mongo/db/query/plan_summary_stats.h index a0ded1f2755..a5ff98266d2 100644 --- a/src/mongo/db/query/plan_summary_stats.h +++ b/src/mongo/db/query/plan_summary_stats.h @@ -72,7 +72,7 @@ struct PlanSummaryStats { bool fromMultiPlanner = false; // Was a replan triggered during the execution of this query? - bool replanned = false; + std::optional<std::string> replanReason; }; } // namespace mongo diff --git a/src/mongo/db/sorter/sorter.cpp b/src/mongo/db/sorter/sorter.cpp index 3d85948fe27..41675b140df 100644 --- a/src/mongo/db/sorter/sorter.cpp +++ b/src/mongo/db/sorter/sorter.cpp @@ -600,10 +600,8 @@ private: // elsewhere where extSortAllowed could possibly be false, this message will // need to be revisited. uasserted(16819, - str::stream() - << "Sort exceeded memory limit of " << _opts.maxMemoryUsageBytes - << " bytes, but did not opt in to external sorting. Aborting operation." - << " Pass allowDiskUse:true to opt in."); + str::stream() << "Sort exceeded memory limit of " << _opts.maxMemoryUsageBytes + << " bytes, but did not opt in to external sorting."); } sort(); |