summaryrefslogtreecommitdiff
path: root/src/mongo/db/query
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/query')
-rw-r--r--src/mongo/db/query/canonical_query.h5
-rw-r--r--src/mongo/db/query/get_executor.cpp31
-rw-r--r--src/mongo/db/query/projection_parser.cpp4
-rw-r--r--src/mongo/db/query/sort_pattern.cpp4
-rw-r--r--src/mongo/db/query/stage_builder.cpp6
5 files changed, 26 insertions, 24 deletions
diff --git a/src/mongo/db/query/canonical_query.h b/src/mongo/db/query/canonical_query.h
index ca5199e3502..39a6ac8ec47 100644
--- a/src/mongo/db/query/canonical_query.h
+++ b/src/mongo/db/query/canonical_query.h
@@ -208,9 +208,12 @@ public:
return _canHaveNoopMatchNodes;
}
- const boost::intrusive_ptr<ExpressionContext>& getExpCtx() const {
+ auto& getExpCtx() const {
return _expCtx;
}
+ auto getExpCtxRaw() const {
+ return _expCtx.get();
+ }
private:
// You must go through canonicalize to create a CanonicalQuery.
diff --git a/src/mongo/db/query/get_executor.cpp b/src/mongo/db/query/get_executor.cpp
index dbbecb419b5..9a512acafdb 100644
--- a/src/mongo/db/query/get_executor.cpp
+++ b/src/mongo/db/query/get_executor.cpp
@@ -385,7 +385,7 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx,
"Collection {ns} does not exist. Using EOF plan: {canonicalQuery_Short}",
"ns"_attr = ns,
"canonicalQuery_Short"_attr = redact(canonicalQuery->toStringShort()));
- root = std::make_unique<EOFStage>(canonicalQuery->getExpCtx().get());
+ root = std::make_unique<EOFStage>(canonicalQuery->getExpCtxRaw());
return PrepareExecutionResult(std::move(canonicalQuery), nullptr, std::move(root));
}
@@ -411,12 +411,12 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx,
"canonicalQuery_Short"_attr = redact(canonicalQuery->toStringShort()));
root = std::make_unique<IDHackStage>(
- canonicalQuery->getExpCtx().get(), canonicalQuery.get(), ws, descriptor);
+ canonicalQuery->getExpCtxRaw(), canonicalQuery.get(), ws, descriptor);
// Might have to filter out orphaned docs.
if (plannerParams.options & QueryPlannerParams::INCLUDE_SHARD_FILTER) {
root = std::make_unique<ShardFilterStage>(
- canonicalQuery->getExpCtx().get(),
+ canonicalQuery->getExpCtxRaw(),
CollectionShardingState::get(opCtx, canonicalQuery->nss())
->getOwnershipFilter(
opCtx,
@@ -430,7 +430,7 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx,
// Add a SortKeyGeneratorStage if the query requested sortKey metadata.
if (canonicalQuery->metadataDeps()[DocumentMetadataFields::kSortKey]) {
root = std::make_unique<SortKeyGeneratorStage>(
- canonicalQuery->getExpCtx().get(),
+ canonicalQuery->getExpCtxRaw(),
std::move(root),
ws,
canonicalQuery->getQueryRequest().getSort());
@@ -442,7 +442,7 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx,
// the exception the $meta sortKey projection, which can be used along with the
// returnKey.
root = std::make_unique<ReturnKeyStage>(
- canonicalQuery->getExpCtx().get(),
+ canonicalQuery->getExpCtxRaw(),
cqProjection
? QueryPlannerCommon::extractSortKeyMetaFieldsFromProjection(*cqProjection)
: std::vector<FieldPath>{},
@@ -462,7 +462,7 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx,
std::move(root));
} else {
root = std::make_unique<ProjectionStageSimple>(
- canonicalQuery->getExpCtx().get(),
+ canonicalQuery->getExpCtxRaw(),
canonicalQuery->getQueryRequest().getProj(),
canonicalQuery->getProj(),
ws,
@@ -518,7 +518,7 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx,
// 'decisionWorks' is used to determine whether the existing cache entry should
// be evicted, and the query replanned.
auto cachedPlanStage =
- std::make_unique<CachedPlanStage>(canonicalQuery->getExpCtx().get(),
+ std::make_unique<CachedPlanStage>(canonicalQuery->getExpCtxRaw(),
collection,
ws,
canonicalQuery.get(),
@@ -540,7 +540,7 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx,
"canonicalQuery_Short"_attr = redact(canonicalQuery->toStringShort()));
root = std::make_unique<SubplanStage>(
- canonicalQuery->getExpCtx().get(), collection, ws, plannerParams, canonicalQuery.get());
+ canonicalQuery->getExpCtxRaw(), collection, ws, plannerParams, canonicalQuery.get());
return PrepareExecutionResult(std::move(canonicalQuery), nullptr, std::move(root));
}
@@ -593,7 +593,7 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx,
// Many solutions. Create a MultiPlanStage to pick the best, update the cache,
// and so on. The working set will be shared by all candidate plans.
auto multiPlanStage = std::make_unique<MultiPlanStage>(
- canonicalQuery->getExpCtx().get(), collection, canonicalQuery.get());
+ canonicalQuery->getExpCtxRaw(), collection, canonicalQuery.get());
for (size_t ix = 0; ix < solutions.size(); ++ix) {
if (solutions[ix]->cacheData.get()) {
@@ -870,7 +870,7 @@ StatusWith<unique_ptr<PlanExecutor, PlanExecutor::Deleter>> getExecutorDelete(
invariant(root);
root = std::make_unique<DeleteStage>(
- cq->getExpCtx().get(), std::move(deleteStageParams), ws.get(), collection, root.release());
+ cq->getExpCtxRaw(), std::move(deleteStageParams), ws.get(), collection, root.release());
if (projection) {
root = std::make_unique<ProjectionStageDefault>(
@@ -1037,12 +1037,11 @@ StatusWith<unique_ptr<PlanExecutor, PlanExecutor::Deleter>> getExecutorUpdate(
updateStageParams.canonicalQuery = cq.get();
const bool isUpsert = updateStageParams.request->isUpsert();
- root =
- (isUpsert
- ? std::make_unique<UpsertStage>(
- cq->getExpCtx().get(), updateStageParams, ws.get(), collection, root.release())
- : std::make_unique<UpdateStage>(
- cq->getExpCtx().get(), updateStageParams, ws.get(), collection, root.release()));
+ root = (isUpsert
+ ? std::make_unique<UpsertStage>(
+ cq->getExpCtxRaw(), updateStageParams, ws.get(), collection, root.release())
+ : std::make_unique<UpdateStage>(
+ cq->getExpCtxRaw(), updateStageParams, ws.get(), collection, root.release()));
if (projection) {
root = std::make_unique<ProjectionStageDefault>(
diff --git a/src/mongo/db/query/projection_parser.cpp b/src/mongo/db/query/projection_parser.cpp
index 5d7d2517287..54f050b7353 100644
--- a/src/mongo/db/query/projection_parser.cpp
+++ b/src/mongo/db/query/projection_parser.cpp
@@ -295,7 +295,7 @@ bool attemptToParseGenericExpression(ParseContext* parseCtx,
}
auto expr = Expression::parseExpression(
- parseCtx->expCtx, subObj, parseCtx->expCtx->variablesParseState);
+ parseCtx->expCtx.get(), subObj, parseCtx->expCtx->variablesParseState);
addNodeAtPath(parent, path, std::make_unique<ExpressionASTNode>(expr));
parseCtx->hasMeta = parseCtx->hasMeta || isMeta;
return true;
@@ -468,7 +468,7 @@ void parseExclusion(ParseContext* ctx, BSONElement elem, ProjectionPathASTNode*
void parseLiteral(ParseContext* ctx, BSONElement elem, ProjectionPathASTNode* parent) {
verifyComputedFieldsAllowed(ctx->policies);
- auto expr = Expression::parseOperand(ctx->expCtx, elem, ctx->expCtx->variablesParseState);
+ auto expr = Expression::parseOperand(ctx->expCtx.get(), elem, ctx->expCtx->variablesParseState);
FieldPath pathFromParent(elem.fieldNameStringData());
addNodeAtPath(parent, pathFromParent, std::make_unique<ExpressionASTNode>(expr));
diff --git a/src/mongo/db/query/sort_pattern.cpp b/src/mongo/db/query/sort_pattern.cpp
index 99590ba1275..a7fff3f9061 100644
--- a/src/mongo/db/query/sort_pattern.cpp
+++ b/src/mongo/db/query/sort_pattern.cpp
@@ -64,8 +64,8 @@ SortPattern::SortPattern(const BSONObj& obj,
} else {
uasserted(31138, str::stream() << "Illegal $meta sort: " << metaElem);
}
- patternPart.expression =
- static_cast<ExpressionMeta*>(ExpressionMeta::parse(pExpCtx, metaElem, vps).get());
+ patternPart.expression = static_cast<ExpressionMeta*>(
+ ExpressionMeta::parse(pExpCtx.get(), metaElem, vps).get());
// If sorting by textScore, sort highest scores first. If sorting by randVal, order
// doesn't matter, so just always use descending.
diff --git a/src/mongo/db/query/stage_builder.cpp b/src/mongo/db/query/stage_builder.cpp
index 3b9dad99a0f..4434c97d928 100644
--- a/src/mongo/db/query/stage_builder.cpp
+++ b/src/mongo/db/query/stage_builder.cpp
@@ -74,7 +74,7 @@ std::unique_ptr<PlanStage> buildStages(OperationContext* opCtx,
const QuerySolution& qsol,
const QuerySolutionNode* root,
WorkingSet* ws) {
- auto* const expCtx = cq.getExpCtx().get();
+ auto* const expCtx = cq.getExpCtxRaw();
switch (root->getType()) {
case STAGE_COLLSCAN: {
const CollectionScanNode* csn = static_cast<const CollectionScanNode*>(root);
@@ -171,7 +171,7 @@ std::unique_ptr<PlanStage> buildStages(OperationContext* opCtx,
case STAGE_PROJECTION_COVERED: {
auto pn = static_cast<const ProjectionNodeCovered*>(root);
auto childStage = buildStages(opCtx, collection, cq, qsol, pn->children[0], ws);
- return std::make_unique<ProjectionStageCovered>(cq.getExpCtx().get(),
+ return std::make_unique<ProjectionStageCovered>(cq.getExpCtxRaw(),
cq.getQueryRequest().getProj(),
cq.getProj(),
ws,
@@ -181,7 +181,7 @@ std::unique_ptr<PlanStage> buildStages(OperationContext* opCtx,
case STAGE_PROJECTION_SIMPLE: {
auto pn = static_cast<const ProjectionNodeSimple*>(root);
auto childStage = buildStages(opCtx, collection, cq, qsol, pn->children[0], ws);
- return std::make_unique<ProjectionStageSimple>(cq.getExpCtx().get(),
+ return std::make_unique<ProjectionStageSimple>(cq.getExpCtxRaw(),
cq.getQueryRequest().getProj(),
cq.getProj(),
ws,