diff options
Diffstat (limited to 'src/mongo/db/pipeline/expression_context.h')
| -rw-r--r-- | src/mongo/db/pipeline/expression_context.h | 120 |
1 files changed, 16 insertions, 104 deletions
diff --git a/src/mongo/db/pipeline/expression_context.h b/src/mongo/db/pipeline/expression_context.h index aa2d212f53d..3f83fba6c8e 100644 --- a/src/mongo/db/pipeline/expression_context.h +++ b/src/mongo/db/pipeline/expression_context.h @@ -60,6 +60,15 @@ namespace mongo { class AggregateCommandRequest; +/** + * The structure ExpressionCounters encapsulates counters for match, aggregate, and other + * expression types as seen in the end-user queries. + */ +struct ExpressionCounters { + StringMap<uint64_t> aggExprCountersMap; + StringMap<uint64_t> matchExprCountersMap; +}; + class ExpressionContext : public RefCountable { public: struct ResolvedNamespace { @@ -109,21 +118,9 @@ public: struct ExpressionCounters { StringMap<uint64_t> aggExprCountersMap; StringMap<uint64_t> matchExprCountersMap; - StringMap<uint64_t> groupAccumulatorExprCountersMap; - StringMap<uint64_t> windowAccumulatorExprCountersMap; }; /** - * Constructs an ExpressionContext to be used for find command parsing and evaluation. - */ - ExpressionContext(OperationContext* opCtx, - const FindCommandRequest& findCmd, - std::unique_ptr<CollatorInterface> collator, - bool mayDbProfile, - boost::optional<ExplainOptions::Verbosity> verbosity = boost::none, - bool allowDiskUseByDefault = false); - - /** * Constructs an ExpressionContext to be used for Pipeline parsing and evaluation. * 'resolvedNamespaces' maps collection names (not full namespaces) to ResolvedNamespaces. */ @@ -171,22 +168,6 @@ public: boost::optional<ExplainOptions::Verbosity> explain = boost::none); /** - * Constructs a blank ExpressionContext suitable for creating Query Shapes, but it could be - * applied to other use cases as well. - * - * The process for creating a Query Shape sometimes requires re-parsing the BSON into a proper - * AST, and for that you need an ExpressionContext. - * - * Note: this is meant for introspection and is not suitable for using to execute queries - - * since it does not contain for example a collation argument or a real MongoProcessInterface - * for execution. - */ - static boost::intrusive_ptr<ExpressionContext> makeBlankExpressionContext( - OperationContext* opCtx, - const NamespaceStringOrUUID& nssOrUUID, - boost::optional<BSONObj> shapifiedLet = boost::none); - - /** * Used by a pipeline to check for interrupts so that killOp() works. Throws a UserAssertion if * this aggregation pipeline has been interrupted. */ @@ -304,8 +285,7 @@ public: */ const ResolvedNamespace& getResolvedNamespace(const NamespaceString& nss) const { auto it = _resolvedNamespaces.find(nss.coll()); - invariant(it != _resolvedNamespaces.end(), - str::stream() << "No resolved namespace provided for " << nss.toString()); + invariant(it != _resolvedNamespaces.end()); return it->second; }; @@ -350,8 +330,10 @@ public: * created yet. Initializes the Scope with the 'jsScope' variables from the runtimeConstants. * Loads the Scope with the functions stored in system.js if the expression isn't executed on * mongos and is called from a MapReduce command or `forceLoadOfStoredProcedures` is true. + * + * Returns a JsExec and a boolean indicating whether the Scope was created as part of this call. */ - JsExecution* getJsExecWithScope(bool forceLoadOfStoredProcedures = false) const { + auto getJsExecWithScope(bool forceLoadOfStoredProcedures = false) const { uassert(31264, "Cannot run server-side javascript without the javascript engine enabled", getGlobalScriptEngine()); @@ -373,17 +355,9 @@ public: "$where."); } - // If there is a cached JsExecution object, return it. This is a performance optimization - // that avoids potentially copying the scope object, which is not needed if a cached exec - // object already exists. - JsExecution* jsExec = JsExecution::getCached(opCtx, loadStoredProcedures); - if (jsExec) { - return jsExec; - } - - BSONObj scopeObj = BSONObj(); + auto scopeObj = BSONObj(); if (variables.hasValue(Variables::kJsScopeId)) { - Value scopeVar = variables.getValue(Variables::kJsScopeId); + auto scopeVar = variables.getValue(Variables::kJsScopeId); invariant(scopeVar.isObject()); scopeObj = scopeVar.getDocument().toBson(); } @@ -406,16 +380,6 @@ public: void incrementAggExprCounter(StringData name); /** - * Increment the counter for the $group accumulator expression with a given name. - */ - void incrementGroupAccumulatorExprCounter(StringData name); - - /** - * Increment the counter for the $setWindowFields accumulator expression with a given name. - */ - void incrementWindowAccumulatorExprCounter(StringData name); - - /** * Merge expression counters from the current expression context into the global maps * and stop counting. */ @@ -469,7 +433,7 @@ public: // Tracks the depth of nested aggregation sub-pipelines. Used to enforce depth limits. long long subPipelineDepth = 0; - // True if this 'ExpressionContext' object is for the inner side of a $lookup or $graphLookup. + // True if this 'ExpressionContext' object is for the inner side of a $lookup. bool inLookup = false; // If set, this will disallow use of features introduced in versions above the provided version. @@ -522,48 +486,6 @@ public: // expression counting. bool enabledCounters = true; - // Sets or clears a flag which tells DocumentSource parsers whether any involved Collection - // may contain extended-range dates. - void setRequiresTimeseriesExtendedRangeSupport(bool v) { - _requiresTimeseriesExtendedRangeSupport = v; - } - bool getRequiresTimeseriesExtendedRangeSupport() const { - return _requiresTimeseriesExtendedRangeSupport; - } - - // This is state that is to be shared between the DocumentInternalSearchMongotRemote and - // DocumentInternalSearchIdLookup stages (these stages are the result of desugaring $search) - // during runtime. - class SharedSearchState { - public: - SharedSearchState() {} - - long long getDocsReturnedByIdLookup() const { - return _docsReturnedByIdLookup; - } - - /** - * Sets the value of _docsReturnedByIdLookup to 0. - */ - void resetDocsReturnedByIdLookup() { - _docsReturnedByIdLookup = 0; - } - - /** - * Increments the value of _docsReturnedByIdLookup by 1. - */ - void incrementDocsReturnedByIdLookup() { - _docsReturnedByIdLookup++; - } - - private: - // When there is an extractable limit in the query, DocumentInternalSearchMongotRemote sends - // a getMore to mongot that specifies how many more documents it needs to fulfill that - // limit, and it incorporates the amount of documents returned by the - // DocumentInternalSearchIdLookup stage into that value. - long long _docsReturnedByIdLookup = 0; - } sharedSearchState; - protected: static const int kInterruptCheckPeriod = 128; @@ -588,17 +510,7 @@ protected: bool _isCappedDelete = false; - bool _requiresTimeseriesExtendedRangeSupport = false; - private: - // Instantiates an ExpressionContext which does not increment expression counters and does not - // enforce FCV restrictions. It is used for implementing the `makeBlankExpressionContext()` - // factory method. Please also note that the runtime constants are not given real/accurate - // values of '$$NOW' and '$$CLUSTER_TIME', in the name of efficiency. - ExpressionContext(OperationContext* opCtx, - const NamespaceString& ns, - const boost::optional<BSONObj>& letParameters = boost::none); - boost::optional<ExpressionCounters> _expressionCounters = boost::none; }; |
