本文整理汇总了C++中pickBestPlan函数的典型用法代码示例。如果您正苦于以下问题:C++ pickBestPlan函数的具体用法?C++ pickBestPlan怎么用?C++ pickBestPlan使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pickBestPlan函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void run() {
// We insert lots of copies of {a:1, b:1, c: 20}. We have the indices {a:1} and {b:1},
// and the query is {a:1, b:1, c: 999}. No data that matches the query but we won't
// know that during plan ranking. We don't want to choose an intersection plan here.
for (int i = 0; i < N; ++i) {
insert(BSON("a" << 1 << "b" << 1 << "c" << 20));
}
addIndex(BSON("a" << 1));
addIndex(BSON("b" << 1));
// There is no data that matches this query but we don't know that until EOF.
CanonicalQuery* cq;
BSONObj queryObj = BSON("a" << 1 << "b" << 1 << "c" << 99);
ASSERT(CanonicalQuery::canonicalize(ns, queryObj, &cq).isOK());
ASSERT(NULL != cq);
// Takes ownership of cq.
QuerySolution* soln = pickBestPlan(cq);
// Anti-prefer the intersection plan.
bool bestIsScanOverA = QueryPlannerTestLib::solutionMatches(
"{fetch: {node: {ixscan: {pattern: {a: 1}}}}}",
soln->root.get());
bool bestIsScanOverB = QueryPlannerTestLib::solutionMatches(
"{fetch: {node: {ixscan: {pattern: {b: 1}}}}}",
soln->root.get());
ASSERT(bestIsScanOverA || bestIsScanOverB);
}
示例2: run
void run() {
// Set up the data so that for the query {a: 1, b: 1, c: 1}, the intersection
// between 'b' and 'c' is small, and the other intersections are larger.
for (int i = 0; i < 10; ++i) {
insert(BSON("a" << 1 << "b" << 1 << "c" << 1));
}
for (int i = 0; i < 10; ++i) {
insert(BSON("a" << 2 << "b" << 1 << "c" << 1));
}
for (int i = 0; i < N/2; ++i) {
insert(BSON("a" << 1 << "b" << 1 << "c" << 2));
insert(BSON("a" << 1 << "b" << 2 << "c" << 1));
}
// Add indices on 'a', 'b', and 'c'.
addIndex(BSON("a" << 1));
addIndex(BSON("b" << 1));
addIndex(BSON("c" << 1));
CanonicalQuery* cq;
ASSERT(CanonicalQuery::canonicalize(ns,
fromjson("{a: 1, b: 1, c: 1}"),
&cq).isOK());
ASSERT(NULL != cq);
// Intersection between 'b' and 'c' should hit EOF while the
// other plans are busy fetching documents.
QuerySolution* soln = pickBestPlan(cq);
ASSERT(QueryPlannerTestLib::solutionMatches(
"{fetch: {filter: {a:1}, node: {andSorted: {nodes: ["
"{ixscan: {filter: null, pattern: {b:1}}},"
"{ixscan: {filter: null, pattern: {c:1}}}]}}}}",
soln->root.get()));
}
示例3: getNext
Runner::RunnerState MultiPlanRunner::getNext(BSONObj* objOut) {
if (_failure || _killed) {
return Runner::RUNNER_DEAD;
}
// If we haven't picked the best plan yet...
if (NULL == _bestPlan) {
// TODO: Consider rewriting pickBestPlan to return results as it iterates.
if (!pickBestPlan(NULL)) {
verify(_failure);
return Runner::RUNNER_DEAD;
}
}
if (!_alreadyProduced.empty()) {
WorkingSetID id = _alreadyProduced.front();
_alreadyProduced.pop();
WorkingSetMember* member = _bestPlan->getWorkingSet()->get(id);
// TODO: getOwned?
verify(WorkingSetCommon::fetch(member));
*objOut = member->obj;
_bestPlan->getWorkingSet()->free(id);
return Runner::RUNNER_ADVANCED;
}
return _bestPlan->getNext(objOut);
}
示例4: getNext
Runner::RunnerState MultiPlanRunner::getNext(BSONObj* objOut, DiskLoc* dlOut) {
if (_killed) { return Runner::RUNNER_DEAD; }
if (_failure) { return Runner::RUNNER_ERROR; }
// If we haven't picked the best plan yet...
if (NULL == _bestPlan) {
if (!pickBestPlan(NULL)) {
verify(_failure || _killed);
if (_killed) { return Runner::RUNNER_DEAD; }
if (_failure) { return Runner::RUNNER_ERROR; }
}
}
if (!_alreadyProduced.empty()) {
WorkingSetID id = _alreadyProduced.front();
_alreadyProduced.pop_front();
WorkingSetMember* member = _bestPlan->getWorkingSet()->get(id);
// Note that this copies code from PlanExecutor.
if (NULL != objOut) {
if (WorkingSetMember::LOC_AND_IDX == member->state) {
if (1 != member->keyData.size()) {
_bestPlan->getWorkingSet()->free(id);
return Runner::RUNNER_ERROR;
}
*objOut = member->keyData[0].keyData;
}
else if (member->hasObj()) {
*objOut = member->obj;
}
else {
// TODO: Checking the WSM for covered fields goes here.
_bestPlan->getWorkingSet()->free(id);
return Runner::RUNNER_ERROR;
}
}
if (NULL != dlOut) {
if (member->hasLoc()) {
*dlOut = member->loc;
}
else {
_bestPlan->getWorkingSet()->free(id);
return Runner::RUNNER_ERROR;
}
}
_bestPlan->getWorkingSet()->free(id);
return Runner::RUNNER_ADVANCED;
}
return _bestPlan->getNext(objOut, dlOut);
}
示例5: getNext
Runner::RunnerState MultiPlanRunner::getNext(BSONObj* objOut, DiskLoc* dlOut) {
if (_killed) { return Runner::RUNNER_DEAD; }
if (_failure) { return Runner::RUNNER_ERROR; }
// If we haven't picked the best plan yet...
if (NULL == _bestPlan) {
if (!pickBestPlan(NULL, objOut)) {
verify(_failure || _killed);
if (_killed) { return Runner::RUNNER_DEAD; }
if (_failure) { return Runner::RUNNER_ERROR; }
}
}
// Look for an already produced result that provides the data the caller wants.
while (!_alreadyProduced.empty()) {
WorkingSetID id = _alreadyProduced.front();
_alreadyProduced.pop_front();
WorkingSetMember* member = _bestPlan->getWorkingSet()->get(id);
// Note that this copies code from PlanExecutor.
if (NULL != objOut) {
if (WorkingSetMember::LOC_AND_IDX == member->state) {
if (1 != member->keyData.size()) {
_bestPlan->getWorkingSet()->free(id);
// If the caller needs the key data and the WSM doesn't have it, drop the
// result and carry on.
continue;
}
*objOut = member->keyData[0].keyData;
}
else if (member->hasObj()) {
*objOut = member->obj;
}
else {
// If the caller needs an object and the WSM doesn't have it, drop and
// try the next result.
_bestPlan->getWorkingSet()->free(id);
continue;
}
}
if (NULL != dlOut) {
if (member->hasLoc()) {
*dlOut = member->loc;
}
else {
// If the caller needs a DiskLoc and the WSM doesn't have it, drop and carry on.
_bestPlan->getWorkingSet()->free(id);
continue;
}
}
// If we're here, the caller has all the data needed and we've set the out
// parameters. Remove the result from the WorkingSet.
_bestPlan->getWorkingSet()->free(id);
return Runner::RUNNER_ADVANCED;
}
RunnerState state = _bestPlan->getNext(objOut, dlOut);
if (Runner::RUNNER_ERROR == state && (NULL != _backupSolution)) {
QLOG() << "Best plan errored out switching to backup\n";
// Uncache the bad solution if we fall back
// on the backup solution.
//
// XXX: Instead of uncaching we should find a way for the
// cached plan runner to fall back on a different solution
// if the best solution fails. Alternatively we could try to
// defer cache insertion to be after the first produced result.
Database* db = cc().database();
verify(NULL != db);
Collection* collection = db->getCollection(_query->ns());
verify(NULL != collection);
PlanCache* cache = collection->infoCache()->getPlanCache();
cache->remove(*_query);
_bestPlan.reset(_backupPlan);
_backupPlan = NULL;
_bestSolution.reset(_backupSolution);
_backupSolution = NULL;
_alreadyProduced = _backupAlreadyProduced;
return getNext(objOut, dlOut);
}
if (NULL != _backupSolution && Runner::RUNNER_ADVANCED == state) {
QLOG() << "Best plan had a blocking sort, became unblocked, deleting backup plan\n";
delete _backupSolution;
delete _backupPlan;
_backupSolution = NULL;
_backupPlan = NULL;
// TODO: free from WS?
_backupAlreadyProduced.clear();
}
return state;
}