Permalink
Browse files

SERVER-12868 renamed QuerySolution::hasSortStage to more generic hasB…

…lockingStage
  • Loading branch information...
1 parent 94cbec5 commit 80fcae04c76b2d7264e93a0e1943a47c58b2d821 @benety benety committed Feb 26, 2014
@@ -386,7 +386,7 @@ namespace mongo {
&& !canonicalQuery->getParsed().getSort().isEmpty()) {
// Look for a solution without a blocking sort stage.
for (size_t i = 0; i < solutions.size(); ++i) {
- if (!solutions[i]->hasSortStage) {
+ if (!solutions[i]->hasBlockingStage) {
WorkingSet* ws;
PlanStage* root;
verify(StageBuilder::build(*solutions[i], &root, &ws));
@@ -341,10 +341,10 @@ namespace mongo {
QLOG() << "Winning solution:\n" << _bestSolution->toString() << endl;
size_t backupChild = bestChild;
- if (_bestSolution->hasSortStage && (0 == _alreadyProduced.size())) {
- QLOG() << "Winner has blocked sort, looking for backup plan...\n";
+ if (_bestSolution->hasBlockingStage && (0 == _alreadyProduced.size())) {
+ QLOG() << "Winner has blocking stage, looking for backup plan...\n";
for (size_t i = 0; i < _candidates.size(); ++i) {
- if (!_candidates[i].solution->hasSortStage) {
+ if (!_candidates[i].solution->hasBlockingStage) {
QLOG() << "Candidate " << i << " is backup child\n";
backupChild = i;
_backupSolution = _candidates[i].solution;
@@ -308,11 +308,11 @@ namespace mongo {
entry->sort = pq.getSort().getOwned();
entry->projection = pq.getProj().getOwned();
- // If the winning solution uses a blocking sort, then try and
- // find a fallback solution that has no blocking sort.
- if (solns[0]->hasSortStage) {
+ // If the winning solution uses a blocking stage, then try and
+ // find a fallback solution that has no blocking stage.
+ if (solns[0]->hasBlockingStage) {
for (size_t i = 1; i < solns.size(); ++i) {
- if (!solns[i]->hasSortStage) {
+ if (!solns[i]->hasBlockingStage) {
entry->backupSoln.reset(i);
break;
}
@@ -446,7 +446,12 @@ namespace mongo {
solnRoot = sfn;
}
- solnRoot = analyzeSort(query, params, solnRoot, &soln->hasSortStage);
+ bool hasSortStage = false;
+ solnRoot = analyzeSort(query, params, solnRoot, &hasSortStage);
+
+ // A solution can be blocking if it has a blocking sort stage.
+ soln->hasBlockingStage = hasSortStage;
+
// This can happen if we need to create a blocking sort stage and we're not allowed to.
if (NULL == solnRoot) { return NULL; }
@@ -469,7 +474,7 @@ namespace mongo {
bool cannotKeepFlagged = hasNode(solnRoot, STAGE_TEXT)
|| hasNode(solnRoot, STAGE_GEO_NEAR_2D)
|| hasNode(solnRoot, STAGE_GEO_NEAR_2DSPHERE)
- || (!query.getParsed().getSort().isEmpty() && !soln->hasSortStage);
+ || (!query.getParsed().getSort().isEmpty() && !hasSortStage);
// Only these stages can produce flagged results. A stage has to hold state past one call
// to work(...) in order to possibly flag a result.
@@ -561,7 +566,7 @@ namespace mongo {
// Otherwise, we need to limit the results in the case of a hard limit
// (ie. limit in raw query is negative)
if (0 != query.getParsed().getNumToReturn() &&
- !soln->hasSortStage &&
+ !hasSortStage &&
!query.getParsed().wantMore()) {
LimitNode* limit = new LimitNode();
@@ -764,10 +764,11 @@ namespace mongo {
&& !QueryPlannerCommon::hasNode(query.root(), MatchExpression::TEXT)) {
// See if we have a sort provided from an index already.
+ // This is implied by the presence of a non-blocking solution.
bool usingIndexToSort = false;
for (size_t i = 0; i < out->size(); ++i) {
QuerySolution* soln = (*out)[i];
- if (!soln->hasSortStage) {
+ if (!soln->hasBlockingStage) {
usingIndexToSort = true;
break;
}
@@ -155,7 +155,7 @@ namespace mongo {
* of stages.
*/
struct QuerySolution {
- QuerySolution() : hasSortStage(false), indexFilterApplied(false) { }
+ QuerySolution() : hasBlockingStage(false), indexFilterApplied(false) { }
// Owned here.
scoped_ptr<QuerySolutionNode> root;
@@ -165,9 +165,16 @@ namespace mongo {
string ns;
+ // There are two known scenarios in which a query solution might potentially block:
+ //
+ // Sort stage:
// If the solution has a sort stage, the sort wasn't provided by an index, so we might want
// to scan an index to provide that sort in a non-blocking fashion.
- bool hasSortStage;
+ //
+ // Hashed AND stage:
+ // The hashed AND stage buffers data from multiple index scans and could block. In that case,
+ // we would want to fall back on an alternate non-blocking solution.
+ bool hasBlockingStage;
// Runner executing this solution might be interested in knowing
// if the planning process for this solution was based on filtered indices.

0 comments on commit 80fcae0

Please sign in to comment.