summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Fefer <ivan.fefer@mongodb.com>2023-02-20 09:48:33 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-02-20 14:08:10 +0000
commit89b0377ea5c62e5a72469d6072aaa146a700b2b6 (patch)
treecc614a44b5601a3a0e231d34f66ab64b315a03df
parent19ec50e155805236aa3259a0cbfc83768e29e767 (diff)
downloadmongo-89b0377ea5c62e5a72469d6072aaa146a700b2b6.tar.gz
SERVER-73423 Remove duplicate addition of collection scan in case of clustered collection
-rw-r--r--src/mongo/db/query/query_planner.cpp30
1 files changed, 10 insertions, 20 deletions
diff --git a/src/mongo/db/query/query_planner.cpp b/src/mongo/db/query/query_planner.cpp
index 56b1b989c57..a3245cf6de9 100644
--- a/src/mongo/db/query/query_planner.cpp
+++ b/src/mongo/db/query/query_planner.cpp
@@ -1534,24 +1534,6 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
}
}
}
-
- // The base index is sorted on some key, so it's possible we might want to use
- // a collection scan to provide the sort requested
- if (auto direction = determineClusteredScanDirection(query, params)) {
- auto soln = buildCollscanSoln(query, isTailable, params, direction);
- if (soln) {
- LOGV2_DEBUG(6082401,
- 5,
- "Planner: outputting soln that uses clustered index to "
- "provide sort");
- SolutionCacheData* scd = new SolutionCacheData();
- scd->solnType = SolutionCacheData::COLLSCAN_SOLN;
- scd->wholeIXSolnDir = *direction;
-
- soln->cacheData.reset(scd);
- out.push_back(std::move(soln));
- }
- }
}
// If a projection exists, there may be an index that allows for a covered plan, even if
@@ -1621,7 +1603,8 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
}
if (possibleToCollscan && (collscanRequested || collScanRequired || clusteredCollection)) {
- auto direction = determineCollscanDirection(query, params);
+ auto clusteredScanDirection = determineClusteredScanDirection(query, params);
+ auto direction = clusteredScanDirection.value_or(1);
auto [collscanSoln, collscanNode] =
buildCollscanSolnWithNode(query, isTailable, params, direction);
if (!collscanSoln && collScanRequired) {
@@ -1629,8 +1612,15 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
"Failed to build collection scan soln");
}
+ // We consider collection scan in the following cases:
+ // 1. collScanRequested - specifically requested by caller.
+ // 2. collScanRequired - there are no other possible plans, so we fallback to full scan.
+ // 3. collscanIsBounded - collection is clustered and clustered index is used.
+ // 4. clusteredScanDirection - collection is clustered and sort, provided by clustered
+ // index, is used
if (collscanSoln &&
- (collscanRequested || collScanRequired || collscanIsBounded(collscanNode))) {
+ (collscanRequested || collScanRequired || collscanIsBounded(collscanNode) ||
+ clusteredScanDirection)) {
LOGV2_DEBUG(20984,
5,
"Planner: outputting a collection scan",