summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/expression.h
diff options
context:
space:
mode:
authorKevinCybura <KevinCybura@gmail.com>2018-03-20 14:17:28 -0400
committerCharlie Swanson <charlie.swanson@mongodb.com>2018-04-26 17:25:36 -0400
commitae01d46b2d70ce2491cc01ef131dd101089c6d21 (patch)
treeba45d67ea49159d34886e024b9e1b19695879ecf /src/mongo/db/pipeline/expression.h
parentd881559e5c847bb422687a72ce10c263f1ef68cc (diff)
downloadmongo-ae01d46b2d70ce2491cc01ef131dd101089c6d21.tar.gz
SERVER-25957 Optimize $indexOfArray when array argument is constant.
Signed-off-by: Charlie Swanson <charlie.swanson@mongodb.com> Closes #1229
Diffstat (limited to 'src/mongo/db/pipeline/expression.h')
-rw-r--r--src/mongo/db/pipeline/expression.h31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/mongo/db/pipeline/expression.h b/src/mongo/db/pipeline/expression.h
index 5b4a0286b7c..6cfd4603bac 100644
--- a/src/mongo/db/pipeline/expression.h
+++ b/src/mongo/db/pipeline/expression.h
@@ -728,6 +728,7 @@ public:
Value evaluate(const Document& root) const final;
Value serialize(bool explain) const final;
+ boost::intrusive_ptr<Expression> optimize() final;
const char* getOpName() const final;
};
@@ -1218,13 +1219,39 @@ public:
};
-class ExpressionIndexOfArray final : public ExpressionRangedArity<ExpressionIndexOfArray, 2, 4> {
+class ExpressionIndexOfArray : public ExpressionRangedArity<ExpressionIndexOfArray, 2, 4> {
public:
explicit ExpressionIndexOfArray(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionRangedArity<ExpressionIndexOfArray, 2, 4>(expCtx) {}
- Value evaluate(const Document& root) const final;
+
+ Value evaluate(const Document& root) const;
+ boost::intrusive_ptr<Expression> optimize() final;
const char* getOpName() const final;
+
+protected:
+ struct Arguments {
+ Arguments(Value targetOfSearch, int startIndex, int endIndex)
+ : targetOfSearch(targetOfSearch), startIndex(startIndex), endIndex(endIndex) {}
+
+ Value targetOfSearch;
+ int startIndex;
+ int endIndex;
+ };
+ /**
+ * When given 'operands' which correspond to the arguments to $indexOfArray, evaluates and
+ * validates the target value, starting index, and ending index arguments and returns their
+ * values as a Arguments struct. The starting index and ending index are optional, so as default
+ * 'startIndex' will be 0 and 'endIndex' will be the length of the input array. Throws a
+ * UserException if the values are found to be invalid in some way, e.g. if the indexes are not
+ * numbers.
+ */
+ Arguments evaluateAndValidateArguments(const Document& root,
+ const ExpressionVector& operands,
+ size_t arrayLength) const;
+
+private:
+ class Optimized;
};