Skip to content

Commit

Permalink
SERVER-10026 enum >1 plan, prefer plans with more compound fields whe…
Browse files Browse the repository at this point in the history
…n ranking
  • Loading branch information
Hari Khalsa committed Oct 8, 2013
1 parent 0357798 commit 39fc9f4
Show file tree
Hide file tree
Showing 11 changed files with 552 additions and 282 deletions.
1 change: 1 addition & 0 deletions src/mongo/db/exec/index_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ namespace mongo {
_specificStats.indexBounds = _params.bounds.toBSON();
_specificStats.direction = _params.direction;
_specificStats.isMultiKey = _descriptor->isMultikey();
_specificStats.keyPattern = _descriptor->keyPattern();
}

PlanStage::StageState IndexScan::work(WorkingSetID* out) {
Expand Down
2 changes: 2 additions & 0 deletions src/mongo/db/exec/plan_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ namespace mongo {
// name of the index being used
std::string indexName;

BSONObj keyPattern;

// A BSON (opaque, ie. hands off other than toString() it) representation of the bounds
// used.
BSONObj indexBounds;
Expand Down
8 changes: 7 additions & 1 deletion src/mongo/db/query/index_bounds_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,11 @@ namespace mongo {

while (argidx < argiv.size() && ividx < iv.size()) {
Interval::IntervalComparison cmp = argiv[argidx].compare(iv[ividx]);
/*
cout << "comparing " << argiv[argidx].toString()
<< " with " << iv[ividx].toString()
<< " cmp is " << Interval::cmpstr(cmp) << endl;
*/

verify(Interval::INTERVAL_UNKNOWN != cmp);

Expand Down Expand Up @@ -429,6 +431,10 @@ namespace mongo {

// Step 2: Walk through and merge.
vector<Interval>& iv = oilOut->intervals;

// This can happen.
if (iv.empty()) { return; }

size_t i = 0;
while (i < iv.size() - 1) {
// Compare i with i + 1.
Expand Down Expand Up @@ -520,7 +526,7 @@ namespace mongo {

const string start = simpleRegex(rme->getString().c_str(), rme->getFlags().c_str(), exact);

cout << "regex bounds start is " << start << endl;
// cout << "regex bounds start is " << start << endl;
// Note that 'exact' is set by simpleRegex above.
if (!start.empty()) {
string end = start;
Expand Down
6 changes: 4 additions & 2 deletions src/mongo/db/query/multi_plan_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ namespace mongo {
}

bool MultiPlanRunner::workAllPlans() {
bool planHitEOF = false;

for (size_t i = 0; i < _candidates.size(); ++i) {
CandidatePlan& candidate = _candidates[i];
if (candidate.failed) { continue; }
Expand Down Expand Up @@ -303,7 +305,7 @@ namespace mongo {
else if (PlanStage::IS_EOF == state) {
// First plan to hit EOF wins automatically. Stop evaluating other plans.
// Assumes that the ranking will pick this plan.
return false;
planHitEOF = true;
}
else {
// FAILURE. Do we want to just tank that plan and try the rest? We probably want
Expand All @@ -327,7 +329,7 @@ namespace mongo {
}
}

return true;
return !planHitEOF;
}

void MultiPlanRunner::allPlansSaveState() {
Expand Down
3 changes: 3 additions & 0 deletions src/mongo/db/query/new_find.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ namespace mongo {
options |= QueryPlanner::NO_TABLE_SCAN;
}
}
else {
options |= QueryPlanner::INCLUDE_COLLSCAN;
}
QueryPlanner::plan(*canonicalQuery, indices, options, &solutions);

/*
Expand Down
Loading

0 comments on commit 39fc9f4

Please sign in to comment.