本文整理汇总了C++中PlanCache::deactivate方法的典型用法代码示例。如果您正苦于以下问题:C++ PlanCache::deactivate方法的具体用法?C++ PlanCache::deactivate怎么用?C++ PlanCache::deactivate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PlanCache
的用法示例。
在下文中一共展示了PlanCache::deactivate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: replan
Status CachedPlanStage::replan(PlanYieldPolicy* yieldPolicy, bool shouldCache) {
// We're going to start over with a new plan. Clear out info from our old plan.
{
std::queue<WorkingSetID> emptyQueue;
_results.swap(emptyQueue);
}
_ws->clear();
_children.clear();
_specificStats.replanned = true;
if (shouldCache) {
// Deactivate the current cache entry.
PlanCache* cache = collection()->infoCache()->getPlanCache();
cache->deactivate(*_canonicalQuery);
}
// Use the query planning module to plan the whole query.
auto statusWithSolutions = QueryPlanner::plan(*_canonicalQuery, _plannerParams);
if (!statusWithSolutions.isOK()) {
return Status(ErrorCodes::BadValue,
str::stream() << "error processing query: " << _canonicalQuery->toString()
<< " planner returned error: "
<< statusWithSolutions.getStatus().reason());
}
auto solutions = std::move(statusWithSolutions.getValue());
// We cannot figure out how to answer the query. Perhaps it requires an index
// we do not have?
if (0 == solutions.size()) {
return Status(ErrorCodes::BadValue,
str::stream() << "error processing query: " << _canonicalQuery->toString()
<< " No query solutions");
}
if (1 == solutions.size()) {
PlanStage* newRoot;
// Only one possible plan. Build the stages from the solution.
verify(StageBuilder::build(
getOpCtx(), collection(), *_canonicalQuery, *solutions[0], _ws, &newRoot));
_children.emplace_back(newRoot);
_replannedQs = std::move(solutions.back());
solutions.pop_back();
LOG(1)
<< "Replanning of query resulted in single query solution, which will not be cached. "
<< redact(_canonicalQuery->toStringShort())
<< " plan summary after replan: " << Explain::getPlanSummary(child().get())
<< " previous cache entry evicted: " << (shouldCache ? "yes" : "no");
return Status::OK();
}
// Many solutions. Create a MultiPlanStage to pick the best, update the cache,
// and so on. The working set will be shared by all candidate plans.
auto cachingMode = shouldCache ? MultiPlanStage::CachingMode::AlwaysCache
: MultiPlanStage::CachingMode::NeverCache;
_children.emplace_back(
new MultiPlanStage(getOpCtx(), collection(), _canonicalQuery, cachingMode));
MultiPlanStage* multiPlanStage = static_cast<MultiPlanStage*>(child().get());
for (size_t ix = 0; ix < solutions.size(); ++ix) {
if (solutions[ix]->cacheData.get()) {
solutions[ix]->cacheData->indexFilterApplied = _plannerParams.indexFiltersApplied;
}
PlanStage* nextPlanRoot;
verify(StageBuilder::build(
getOpCtx(), collection(), *_canonicalQuery, *solutions[ix], _ws, &nextPlanRoot));
// Takes ownership of 'nextPlanRoot'.
multiPlanStage->addPlan(std::move(solutions[ix]), nextPlanRoot, _ws);
}
// Delegate to the MultiPlanStage's plan selection facility.
Status pickBestPlanStatus = multiPlanStage->pickBestPlan(yieldPolicy);
if (!pickBestPlanStatus.isOK()) {
return pickBestPlanStatus;
}
LOG(1) << "Replanning " << redact(_canonicalQuery->toStringShort())
<< " resulted in plan with summary: " << Explain::getPlanSummary(child().get())
<< ", which " << (shouldCache ? "has" : "has not") << " been written to the cache";
return Status::OK();
}