diff options
Diffstat (limited to 'src/mongo/db/query/canonical_query.cpp')
-rw-r--r-- | src/mongo/db/query/canonical_query.cpp | 59 |
1 files changed, 15 insertions, 44 deletions
diff --git a/src/mongo/db/query/canonical_query.cpp b/src/mongo/db/query/canonical_query.cpp index 3a411c6925b..d632f9141ba 100644 --- a/src/mongo/db/query/canonical_query.cpp +++ b/src/mongo/db/query/canonical_query.cpp @@ -52,13 +52,6 @@ namespace mongo { namespace { -bool parsingCanProduceNoopMatchNodes(const ExtensionsCallback& extensionsCallback, - MatchExpressionParser::AllowedFeatureSet allowedFeatures) { - return extensionsCallback.hasNoopExtensions() && - (allowedFeatures & MatchExpressionParser::AllowedFeatures::kText || - allowedFeatures & MatchExpressionParser::AllowedFeatures::kJavascript); -} - boost::optional<size_t> loadMaxParameterCount() { auto value = internalQueryAutoParameterizationMaxParameterCount.load(); if (value > 0) { @@ -116,38 +109,25 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( std::unique_ptr<CanonicalQuery> cq(new CanonicalQuery()); cq->setExplain(explain); - StatusWithMatchExpression statusWithMatcher = [&]() -> StatusWithMatchExpression { - if (getTestCommandsEnabled() && internalQueryEnableCSTParser.load()) { - try { - return cst::parseToMatchExpression( - findCommand->getFilter(), newExpCtx, extensionsCallback); - } catch (const DBException& ex) { - return ex.toStatus(); - } - } else { - return MatchExpressionParser::parse( - findCommand->getFilter(), newExpCtx, extensionsCallback, allowedFeatures); - } - }(); + auto statusWithMatcher = MatchExpressionParser::parse( + findCommand->getFilter(), newExpCtx, extensionsCallback, allowedFeatures); if (!statusWithMatcher.isOK()) { return statusWithMatcher.getStatus(); } + std::unique_ptr<MatchExpression> me = std::move(statusWithMatcher.getValue()); + // Stop counting expressions after they have been parsed to exclude expressions created // during optimization and other processing steps. newExpCtx->stopExpressionCounters(); - std::unique_ptr<MatchExpression> me = std::move(statusWithMatcher.getValue()); - - Status initStatus = - cq->init(opCtx, - std::move(newExpCtx), - std::move(findCommand), - parsingCanProduceNoopMatchNodes(extensionsCallback, allowedFeatures), - std::move(me), - projectionPolicies, - std::move(pipeline), - isCountLike); + Status initStatus = cq->init(opCtx, + std::move(newExpCtx), + std::move(findCommand), + std::move(me), + projectionPolicies, + std::move(pipeline), + isCountLike); if (!initStatus.isOK()) { return initStatus; @@ -174,7 +154,6 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( Status initStatus = cq->init(opCtx, baseQuery.getExpCtx(), std::move(findCommand), - baseQuery.canHaveNoopMatchNodes(), root->clone(), ProjectionPolicies::findProjectionPolicies(), {} /* an empty pipeline */, @@ -189,7 +168,6 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( Status CanonicalQuery::init(OperationContext* opCtx, boost::intrusive_ptr<ExpressionContext> expCtx, std::unique_ptr<FindCommandRequest> findCommand, - bool canHaveNoopMatchNodes, std::unique_ptr<MatchExpression> root, const ProjectionPolicies& projectionPolicies, std::vector<std::unique_ptr<InnerPipelineStageInterface>> pipeline, @@ -197,7 +175,6 @@ Status CanonicalQuery::init(OperationContext* opCtx, _expCtx = expCtx; _findCommand = std::move(findCommand); - _canHaveNoopMatchNodes = canHaveNoopMatchNodes; _forceClassicEngine = ServerParameterSet::getNodeParameterSet() ->get<QueryFrameworkControl>("internalQueryFrameworkControl") ->_data.get() == QueryFrameworkControlEnum::kForceClassicEngine; @@ -262,7 +239,9 @@ Status CanonicalQuery::init(OperationContext* opCtx, // If there is a sort, parse it and add any metadata dependencies it induces. try { - initSortPattern(unavailableMetadata); + if (!_findCommand->getSort().isEmpty()) { + initSortPattern(unavailableMetadata); + } } catch (const DBException& ex) { return ex.toStatus(); } @@ -276,10 +255,6 @@ Status CanonicalQuery::init(OperationContext* opCtx, } void CanonicalQuery::initSortPattern(QueryMetadataBitSet unavailableMetadata) { - if (_findCommand->getSort().isEmpty()) { - return; - } - // A $natural sort is really a hint, and should be handled as such. Furthermore, the downstream // sort handling code may not expect a $natural sort. // @@ -291,11 +266,7 @@ void CanonicalQuery::initSortPattern(QueryMetadataBitSet unavailableMetadata) { _findCommand->setSort(BSONObj{}); } - if (getTestCommandsEnabled() && internalQueryEnableCSTParser.load()) { - _sortPattern = cst::parseToSortPattern(_findCommand->getSort(), _expCtx); - } else { - _sortPattern = SortPattern{_findCommand->getSort(), _expCtx}; - } + _sortPattern = SortPattern{_findCommand->getSort(), _expCtx}; _metadataDeps |= _sortPattern->metadataDeps(unavailableMetadata); // If the results of this query might have to be merged on a remote node, then that node might |