本文整理汇总了C++中PlanCache::getEntry方法的典型用法代码示例。如果您正苦于以下问题:C++ PlanCache::getEntry方法的具体用法?C++ PlanCache::getEntry怎么用?C++ PlanCache::getEntry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PlanCache
的用法示例。
在下文中一共展示了PlanCache::getEntry方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ctx
/**
* Test the way cache entries are added (either "active" or "inactive") to the plan cache.
*/
TEST_F(QueryStageCachedPlan, QueryStageCachedPlanAddsActiveCacheEntries) {
AutoGetCollectionForReadCommand ctx(&_opCtx, nss);
Collection* collection = ctx.getCollection();
ASSERT(collection);
// Never run - just used as a key for the cache's get() functions, since all of the other
// CanonicalQueries created in this test will have this shape.
const auto shapeCq =
canonicalQueryFromFilterObj(opCtx(), nss, fromjson("{a: {$gte: 123}, b: {$gte: 123}}"));
// Query can be answered by either index on "a" or index on "b".
const auto noResultsCq =
canonicalQueryFromFilterObj(opCtx(), nss, fromjson("{a: {$gte: 11}, b: {$gte: 11}}"));
// We shouldn't have anything in the plan cache for this shape yet.
PlanCache* cache = collection->infoCache()->getPlanCache();
ASSERT(cache);
ASSERT_EQ(cache->get(*shapeCq).state, PlanCache::CacheEntryState::kNotPresent);
// Run the CachedPlanStage with a long-running child plan. Replanning should be
// triggered and an inactive entry will be added.
forceReplanning(collection, noResultsCq.get());
// Check for an inactive cache entry.
ASSERT_EQ(cache->get(*shapeCq).state, PlanCache::CacheEntryState::kPresentInactive);
// The works should be 1 for the entry since the query we ran should not have any results.
auto entry = assertGet(cache->getEntry(*shapeCq));
size_t works = 1U;
ASSERT_EQ(entry->works, works);
const size_t kExpectedNumWorks = 10;
for (int i = 0; i < std::ceil(std::log(kExpectedNumWorks) / std::log(2)); ++i) {
works *= 2;
// Run another query of the same shape, which is less selective, and therefore takes
// longer).
auto someResultsCq =
canonicalQueryFromFilterObj(opCtx(), nss, fromjson("{a: {$gte: 1}, b: {$gte: 0}}"));
forceReplanning(collection, someResultsCq.get());
ASSERT_EQ(cache->get(*shapeCq).state, PlanCache::CacheEntryState::kPresentInactive);
// The works on the cache entry should have doubled.
entry = assertGet(cache->getEntry(*shapeCq));
ASSERT_EQ(entry->works, works);
}
// Run another query which takes less time, and be sure an active entry is created.
auto fewResultsCq =
canonicalQueryFromFilterObj(opCtx(), nss, fromjson("{a: {$gte: 6}, b: {$gte: 0}}"));
forceReplanning(collection, fewResultsCq.get());
// Now there should be an active cache entry.
ASSERT_EQ(cache->get(*shapeCq).state, PlanCache::CacheEntryState::kPresentActive);
entry = assertGet(cache->getEntry(*shapeCq));
// This will query will match {a: 6} through {a:9} (4 works), plus one for EOF = 5 works.
ASSERT_EQ(entry->works, 5U);
}
示例2: list
// static
Status PlanCacheListPlans::list(OperationContext* opCtx,
const PlanCache& planCache,
const std::string& ns,
const BSONObj& cmdObj,
BSONObjBuilder* bob) {
auto statusWithCQ = canonicalize(opCtx, ns, cmdObj);
if (!statusWithCQ.isOK()) {
return statusWithCQ.getStatus();
}
if (!internalQueryCacheListPlansNewOutput.load())
return listPlansOriginalFormat(std::move(statusWithCQ.getValue()), planCache, bob);
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
auto entry = uassertStatusOK(planCache.getEntry(*cq));
// internalQueryCacheDisableInactiveEntries is True and we should use the new output format.
Explain::planCacheEntryToBSON(*entry, bob);
return Status::OK();
}
示例3: list
// static
Status PlanCacheListPlans::list(OperationContext* txn,
const PlanCache& planCache,
const std::string& ns,
const BSONObj& cmdObj,
BSONObjBuilder* bob) {
CanonicalQuery* cqRaw;
Status status = canonicalize(txn, ns, cmdObj, &cqRaw);
if (!status.isOK()) {
return status;
}
scoped_ptr<CanonicalQuery> cq(cqRaw);
if (!planCache.contains(*cq)) {
// Return empty plans in results if query shape does not
// exist in plan cache.
BSONArrayBuilder plansBuilder(bob->subarrayStart("plans"));
plansBuilder.doneFast();
return Status::OK();
}
PlanCacheEntry* entryRaw;
Status result = planCache.getEntry(*cq, &entryRaw);
if (!result.isOK()) {
return result;
}
scoped_ptr<PlanCacheEntry> entry(entryRaw);
BSONArrayBuilder plansBuilder(bob->subarrayStart("plans"));
size_t numPlans = entry->plannerData.size();
invariant(numPlans == entry->decision->stats.size());
invariant(numPlans == entry->decision->scores.size());
for (size_t i = 0; i < numPlans; ++i) {
BSONObjBuilder planBob(plansBuilder.subobjStart());
// Create plan details field.
// Currently, simple string representationg of
// SolutionCacheData. Need to revisit format when we
// need to parse user-provided plan details for planCacheAddPlan.
SolutionCacheData* scd = entry->plannerData[i];
BSONObjBuilder detailsBob(planBob.subobjStart("details"));
detailsBob.append("solution", scd->toString());
detailsBob.doneFast();
// reason is comprised of score and initial stats provided by
// multi plan runner.
BSONObjBuilder reasonBob(planBob.subobjStart("reason"));
reasonBob.append("score", entry->decision->scores[i]);
BSONObjBuilder statsBob(reasonBob.subobjStart("stats"));
PlanStageStats* stats = entry->decision->stats.vector()[i];
if (stats) {
Explain::statsToBSON(*stats, &statsBob);
}
statsBob.doneFast();
reasonBob.doneFast();
// BSON object for 'feedback' field is created from query executions
// and shows number of executions since this cached solution was
// created as well as score data (average and standard deviation).
BSONObjBuilder feedbackBob(planBob.subobjStart("feedback"));
if (i == 0U) {
feedbackBob.append("nfeedback", int(entry->feedback.size()));
feedbackBob.append("averageScore", entry->averageScore.get_value_or(0));
feedbackBob.append("stdDevScore",entry->stddevScore.get_value_or(0));
BSONArrayBuilder scoresBob(feedbackBob.subarrayStart("scores"));
for (size_t i = 0; i < entry->feedback.size(); ++i) {
BSONObjBuilder scoreBob(scoresBob.subobjStart());
scoreBob.append("score", entry->feedback[i]->score);
}
scoresBob.doneFast();
}
feedbackBob.doneFast();
planBob.append("filterSet", scd->indexFilterApplied);
}
plansBuilder.doneFast();
return Status::OK();
}