summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/canonical_query.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/query/canonical_query.h')
-rw-r--r--src/mongo/db/query/canonical_query.h62
1 files changed, 25 insertions, 37 deletions
diff --git a/src/mongo/db/query/canonical_query.h b/src/mongo/db/query/canonical_query.h
index 79b49c08463..570b71b6fae 100644
--- a/src/mongo/db/query/canonical_query.h
+++ b/src/mongo/db/query/canonical_query.h
@@ -37,6 +37,7 @@
#include "mongo/db/matcher/extensions_callback_noop.h"
#include "mongo/db/pipeline/inner_pipeline_stage_interface.h"
#include "mongo/db/query/collation/collator_interface.h"
+#include "mongo/db/query/parsed_find_command.h"
#include "mongo/db/query/projection.h"
#include "mongo/db/query/projection_policies.h"
#include "mongo/db/query/query_request_helper.h"
@@ -76,6 +77,15 @@ public:
std::vector<std::unique_ptr<InnerPipelineStageInterface>> pipeline = {});
/**
+ * Creates a CanonicalQuery from a ParsedFindCommand. Uses 'expCtx->opCtx', which must be valid.
+ */
+ static StatusWith<std::unique_ptr<CanonicalQuery>> canonicalize(
+ boost::intrusive_ptr<ExpressionContext> expCtx,
+ std::unique_ptr<ParsedFindCommand> parsedFind,
+ bool explain = false,
+ std::vector<std::unique_ptr<InnerPipelineStageInterface>> pipeline = {});
+
+ /**
* For testing or for internal clients to use.
*/
@@ -93,32 +103,22 @@ public:
static bool isSimpleIdQuery(const BSONObj& query);
/**
- * Validates the match expression 'root' as well as the query specified by 'request', checking
- * for illegal combinations of operators. Returns a non-OK status if any such illegal
- * combination is found.
- *
- * This method can be called both on normalized and non-normalized 'root'. However, some checks
- * can only be performed once the match expressions is normalized. To perform these checks one
- * can call 'isValidNormalized()'.
- *
- * On success, returns a bitset indicating which types of metadata are *unavailable*. For
- * example, if 'root' does not contain a $text predicate, then the returned metadata bitset will
- * indicate that text score metadata is unavailable. This means that if subsequent
- * $meta:"textScore" expressions are found during analysis of the query, we should raise in an
- * error.
+ * Perform validation checks on the normalized 'root' which could not be checked before
+ * normalization - those should happen in parsed_find_command::isValid().
*/
- static StatusWith<QueryMetadataBitSet> isValid(const MatchExpression* root,
- const FindCommandRequest& findCommand);
+ static Status isValidNormalized(const MatchExpression* root);
/**
- * Perform additional validation checks on the normalized 'root'.
+ * For internal use only - but public for accessibility for make_unique(). You must go through
+ * canonicalize to create a CanonicalQuery.
*/
- static Status isValidNormalized(const MatchExpression* root);
+ CanonicalQuery() {}
const NamespaceString nss() const {
invariant(_findCommand->getNamespaceOrUUID().nss());
return *_findCommand->getNamespaceOrUUID().nss();
}
+
const std::string ns() const {
return nss().ns();
}
@@ -197,11 +197,6 @@ public:
std::string toStringShort() const;
/**
- * Returns a count of 'type' nodes in expression tree.
- */
- static size_t countNodes(const MatchExpression* root, MatchExpression::MatchType type);
-
- /**
* Returns true if this canonical query may have converted extensions such as $where and $text
* into no-ops during parsing. This will be the case if it allowed $where and $text in parsing,
* but parsed using an ExtensionsCallbackNoop. This does not guarantee that a $where or $text
@@ -262,25 +257,18 @@ public:
return _pipeline;
}
-private:
- // You must go through canonicalize to create a CanonicalQuery.
- CanonicalQuery() {}
+ void optimizeProjection() {
+ if (_proj) {
+ _proj->optimize();
+ }
+ }
- Status init(OperationContext* opCtx,
- boost::intrusive_ptr<ExpressionContext> expCtx,
- std::unique_ptr<FindCommandRequest> findCommand,
- bool canHaveNoopMatchNodes,
- std::unique_ptr<MatchExpression> root,
- const ProjectionPolicies& projectionPolicies,
+private:
+ Status init(boost::intrusive_ptr<ExpressionContext> expCtx,
+ std::unique_ptr<ParsedFindCommand> parsedFind,
std::vector<std::unique_ptr<InnerPipelineStageInterface>> pipeline,
bool optimizeMatchExpression);
- // Initializes '_sortPattern', adding any metadata dependencies implied by the sort.
- //
- // Throws a UserException if the sort is illegal, or if any metadata type in
- // 'unavailableMetadata' is required.
- void initSortPattern(QueryMetadataBitSet unavailableMetadata);
-
boost::intrusive_ptr<ExpressionContext> _expCtx;
std::unique_ptr<FindCommandRequest> _findCommand;