summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilena Ivanova <milena.ivanova@mongodb.com>2021-09-10 17:31:26 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-11-19 11:13:47 +0000
commit12c32474881bb33702b4499555dfe98070f332b1 (patch)
treee42cc09476a52204ee4d3f62887cb4ebc3dff36b
parentbd398d6f3bd394be3281110ac762d070117e21c9 (diff)
downloadmongo-12c32474881bb33702b4499555dfe98070f332b1.tar.gz
SERVER-58192 Use more unique_ptrs in QueryPlannerAnalysis::analyzeSort()
(cherry picked from commit de21bf91f015f0ac21ed691ae0049db35f071920)
-rw-r--r--src/mongo/db/query/planner_analysis.cpp29
-rw-r--r--src/mongo/db/query/query_solution.cpp6
2 files changed, 18 insertions, 17 deletions
diff --git a/src/mongo/db/query/planner_analysis.cpp b/src/mongo/db/query/planner_analysis.cpp
index 059564d783e..b5d1644d3db 100644
--- a/src/mongo/db/query/planner_analysis.cpp
+++ b/src/mongo/db/query/planner_analysis.cpp
@@ -552,21 +552,22 @@ QuerySolutionNode* QueryPlannerAnalysis::analyzeSort(const CanonicalQuery& query
// And build the full sort stage. The sort stage has to have a sort key generating stage
// as its child, supplying it with the appropriate sort keys.
- SortKeyGeneratorNode* keyGenNode = new SortKeyGeneratorNode();
+ auto keyGenNode = std::make_unique<SortKeyGeneratorNode>();
keyGenNode->sortSpec = sortObj;
keyGenNode->children.push_back(solnRoot);
- solnRoot = keyGenNode;
+ solnRoot = keyGenNode.release();
- SortNode* sort = new SortNode();
+ auto sort = std::make_unique<SortNode>();
sort->pattern = sortObj;
sort->children.push_back(solnRoot);
- solnRoot = sort;
+ solnRoot = sort.release();
+ auto sortNodeRaw = static_cast<SortNode*>(solnRoot);
// When setting the limit on the sort, we need to consider both
// the limit N and skip count M. The sort should return an ordered list
// N + M items so that the skip stage can discard the first M results.
if (qr.getLimit()) {
// We have a true limit. The limit can be combined with the SORT stage.
- sort->limit =
+ sortNodeRaw->limit =
static_cast<size_t>(*qr.getLimit()) + static_cast<size_t>(qr.getSkip().value_or(0));
} else if (qr.getNToReturn()) {
// We have an ntoreturn specified by an OP_QUERY style find. This is used
@@ -575,7 +576,7 @@ QuerySolutionNode* QueryPlannerAnalysis::analyzeSort(const CanonicalQuery& query
// Overflow here would be bad and could cause a nonsense limit. Cast
// skip and limit values to unsigned ints to make sure that the
// sum is never stored as signed. (See SERVER-13537).
- sort->limit =
+ sortNodeRaw->limit =
static_cast<size_t>(*qr.getNToReturn()) + static_cast<size_t>(qr.getSkip().value_or(0));
// This is a SORT with a limit. The wire protocol has a single quantity
@@ -610,20 +611,20 @@ QuerySolutionNode* QueryPlannerAnalysis::analyzeSort(const CanonicalQuery& query
//
// Not allowed for geo or text, because we assume elsewhere that those
// stages appear just once.
- OrNode* orn = new OrNode();
- orn->children.push_back(sort);
- SortNode* sortClone = static_cast<SortNode*>(sort->clone());
+ auto orn = std::make_unique<OrNode>();
+ orn->children.push_back(solnRoot);
+ SortNode* sortClone = static_cast<SortNode*>(sortNodeRaw->clone());
sortClone->limit = 0;
orn->children.push_back(sortClone);
// Add ENSURE_SORTED above the OR.
- EnsureSortedNode* esn = new EnsureSortedNode();
- esn->pattern = sort->pattern;
- esn->children.push_back(orn);
- solnRoot = esn;
+ auto esn = std::make_unique<EnsureSortedNode>();
+ esn->pattern = sortNodeRaw->pattern;
+ esn->children.push_back(orn.release());
+ solnRoot = esn.release();
}
} else {
- sort->limit = 0;
+ sortNodeRaw->limit = 0;
}
*blockingSortOut = true;
diff --git a/src/mongo/db/query/query_solution.cpp b/src/mongo/db/query/query_solution.cpp
index 39ab80a4a4b..c287550e5bc 100644
--- a/src/mongo/db/query/query_solution.cpp
+++ b/src/mongo/db/query/query_solution.cpp
@@ -923,14 +923,14 @@ void SortNode::appendToString(mongoutils::str::stream* ss, int indent) const {
}
QuerySolutionNode* SortNode::clone() const {
- SortNode* copy = new SortNode();
- cloneBaseData(copy);
+ auto copy = std::make_unique<SortNode>();
+ cloneBaseData(copy.get());
copy->_sorts = this->_sorts;
copy->pattern = this->pattern;
copy->limit = this->limit;
- return copy;
+ return copy.release();
}
//