diff options
author | Davis Haupt <davis.haupt@mongodb.com> | 2022-03-01 15:40:59 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-03-01 16:53:11 +0000 |
commit | 07d86305627dd60c7a4068f5db5726cd267edab3 (patch) | |
tree | 49ebbefb99600e9fba0053e845bde90c8832694d /src/mongo/db/matcher | |
parent | 9eaa498adf3aba641c079387db9fee56b5d0af9d (diff) | |
download | mongo-07d86305627dd60c7a4068f5db5726cd267edab3.tar.gz |
SERVER-63294 server-side rewrite for match expressions with FLE find payloads
Diffstat (limited to 'src/mongo/db/matcher')
20 files changed, 118 insertions, 82 deletions
diff --git a/src/mongo/db/matcher/expression.h b/src/mongo/db/matcher/expression.h index c87738faaf8..812781a3ad9 100644 --- a/src/mongo/db/matcher/expression.h +++ b/src/mongo/db/matcher/expression.h @@ -354,12 +354,19 @@ public: */ virtual MatchExpression* getChild(size_t index) const = 0; + + /** + * Delegates to the specified child unique_ptr's reset() method in order to replace child + * expressions while traversing the tree. + */ + virtual void resetChild(size_t index, MatchExpression* other) = 0; + /** - * For MatchExpression nodes that can participate in tree restructuring (like AND/OR), returns a - * non-const vector of MatchExpression* child nodes. If the MatchExpression does not - * participated in tree restructuring, returns boost::none. - * Do not use to traverse the MatchExpression tree. Use numChildren() and getChild(), which - * provide access to all nodes. + * For MatchExpression nodes that can participate in tree restructuring (like AND/OR), + * returns a non-const vector of MatchExpression* child nodes. If the MatchExpression does + * not participated in tree restructuring, returns boost::none. Do not use to traverse the + * MatchExpression tree. Use numChildren() and getChild(), which provide access to all + * nodes. */ virtual std::vector<std::unique_ptr<MatchExpression>>* getChildVector() = 0; diff --git a/src/mongo/db/matcher/expression_always_boolean.h b/src/mongo/db/matcher/expression_always_boolean.h index 73dc9be4f0b..6e0e2cdfbc8 100644 --- a/src/mongo/db/matcher/expression_always_boolean.h +++ b/src/mongo/db/matcher/expression_always_boolean.h @@ -82,6 +82,10 @@ public: MONGO_UNREACHABLE; } + void resetChild(size_t, MatchExpression*) override { + MONGO_UNREACHABLE; + } + std::vector<std::unique_ptr<MatchExpression>>* getChildVector() final { return nullptr; } diff --git a/src/mongo/db/matcher/expression_arity.h b/src/mongo/db/matcher/expression_arity.h index 61c03567368..90286200e21 100644 --- a/src/mongo/db/matcher/expression_arity.h +++ b/src/mongo/db/matcher/expression_arity.h @@ -94,6 +94,11 @@ public: return _expressions[i].get(); } + void resetChild(size_t i, MatchExpression* other) override { + tassert(6329406, "Out-of-bounds access to child of MatchExpression.", i < numChildren()); + _expressions[i].reset(other); + } + /** * The name of this MatchExpression. */ diff --git a/src/mongo/db/matcher/expression_array.h b/src/mongo/db/matcher/expression_array.h index ec5e2d76f7f..1b6cb5dfcc9 100644 --- a/src/mongo/db/matcher/expression_array.h +++ b/src/mongo/db/matcher/expression_array.h @@ -104,6 +104,11 @@ public: return _sub.get(); } + virtual void resetChild(size_t i, MatchExpression* other) { + tassert(6329401, "Out-of-bounds access to child of MatchExpression.", i < numChildren()); + _sub.reset(other); + } + std::unique_ptr<MatchExpression> releaseChild() { return std::move(_sub); } @@ -166,6 +171,11 @@ public: return _subs[i].get(); } + virtual void resetChild(size_t i, MatchExpression* other) override { + tassert(6329402, "Out-of-bounds access to child of MatchExpression.", i < numChildren()); + _subs[i].reset(other); + } + void acceptVisitor(MatchExpressionMutableVisitor* visitor) final { visitor->visit(this); } @@ -208,6 +218,10 @@ public: return nullptr; } + void resetChild(size_t i, MatchExpression* other) override { + tassert(6329403, "SizeMatchExpression does not have any children.", i < numChildren()); + } + std::vector<std::unique_ptr<MatchExpression>>* getChildVector() final { return nullptr; } diff --git a/src/mongo/db/matcher/expression_expr.h b/src/mongo/db/matcher/expression_expr.h index 4e9e6dc29ab..281fdd3afd6 100644 --- a/src/mongo/db/matcher/expression_expr.h +++ b/src/mongo/db/matcher/expression_expr.h @@ -38,6 +38,7 @@ #include "mongo/db/pipeline/expression.h" #include "mongo/db/pipeline/expression_context.h" #include "mongo/db/pipeline/expression_walker.h" +#include "mongo/util/assert_util.h" namespace mongo { @@ -90,6 +91,10 @@ public: MONGO_UNREACHABLE; } + void resetChild(size_t, MatchExpression*) { + MONGO_UNREACHABLE; + }; + std::vector<std::unique_ptr<MatchExpression>>* getChildVector() final { return nullptr; } diff --git a/src/mongo/db/matcher/expression_internal_bucket_geo_within.h b/src/mongo/db/matcher/expression_internal_bucket_geo_within.h index 21d4197eda5..2864c71a05e 100644 --- a/src/mongo/db/matcher/expression_internal_bucket_geo_within.h +++ b/src/mongo/db/matcher/expression_internal_bucket_geo_within.h @@ -110,6 +110,10 @@ public: MONGO_UNREACHABLE; } + void resetChild(size_t, MatchExpression*) { + MONGO_UNREACHABLE; + }; + const std::string getField() const { return _field; } diff --git a/src/mongo/db/matcher/expression_leaf.h b/src/mongo/db/matcher/expression_leaf.h index 4359b6f1c3c..4b7a965ce02 100644 --- a/src/mongo/db/matcher/expression_leaf.h +++ b/src/mongo/db/matcher/expression_leaf.h @@ -41,6 +41,7 @@ #include "mongo/db/query/collation/collator_interface.h" #include "mongo/db/query/util/make_data_structure.h" #include "mongo/stdx/unordered_map.h" +#include "mongo/util/assert_util.h" namespace pcrecpp { class RE; @@ -106,6 +107,11 @@ public: MONGO_UNREACHABLE; } + + void resetChild(size_t, MatchExpression*) override { + MONGO_UNREACHABLE; + } + std::vector<std::unique_ptr<MatchExpression>>* getChildVector() final { return nullptr; } diff --git a/src/mongo/db/matcher/expression_tree.h b/src/mongo/db/matcher/expression_tree.h index 5100131dcaa..f8b9179c003 100644 --- a/src/mongo/db/matcher/expression_tree.h +++ b/src/mongo/db/matcher/expression_tree.h @@ -64,6 +64,11 @@ public: return _expressions[i].get(); } + void resetChild(size_t i, MatchExpression* other) override { + tassert(6329404, "Out-of-bounds access to child of MatchExpression.", i < numChildren()); + _expressions[i].reset(other); + } + /* * Replaces the ith child with nullptr, and releases ownership of the child. */ @@ -272,6 +277,7 @@ public: return _exp.get(); } + std::vector<std::unique_ptr<MatchExpression>>* getChildVector() final { return nullptr; } @@ -280,7 +286,8 @@ public: return _exp.release(); } - void resetChild(MatchExpression* newChild) { + void resetChild(size_t i, MatchExpression* newChild) { + tassert(6329405, "Out-of-bounds access to child of MatchExpression.", i < numChildren()); _exp.reset(newChild); } diff --git a/src/mongo/db/matcher/expression_where_base.h b/src/mongo/db/matcher/expression_where_base.h index 1964d818931..550e94d1d37 100644 --- a/src/mongo/db/matcher/expression_where_base.h +++ b/src/mongo/db/matcher/expression_where_base.h @@ -54,6 +54,11 @@ public: MONGO_UNREACHABLE; } + void resetChild(size_t, MatchExpression*) { + MONGO_UNREACHABLE; + }; + + std::vector<std::unique_ptr<MatchExpression>>* getChildVector() final { return nullptr; } diff --git a/src/mongo/db/matcher/expression_with_placeholder.h b/src/mongo/db/matcher/expression_with_placeholder.h index 1a27c0bbcd3..2531c7465d0 100644 --- a/src/mongo/db/matcher/expression_with_placeholder.h +++ b/src/mongo/db/matcher/expression_with_placeholder.h @@ -88,6 +88,10 @@ public: return _filter.get(); } + void resetFilter(MatchExpression* other) { + _filter.reset(other); + } + std::unique_ptr<ExpressionWithPlaceholder> shallowClone() const { return std::make_unique<ExpressionWithPlaceholder>(_placeholder, _filter->shallowClone()); } diff --git a/src/mongo/db/matcher/schema/encrypt_schema.idl b/src/mongo/db/matcher/schema/encrypt_schema.idl index b2a8b2f4918..ca9b1fb64d7 100644 --- a/src/mongo/db/matcher/schema/encrypt_schema.idl +++ b/src/mongo/db/matcher/schema/encrypt_schema.idl @@ -58,28 +58,7 @@ enums: values: kDeterministic: "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic" kRandom: "AEAD_AES_256_CBC_HMAC_SHA_512-Random" - FleAlgorithmInt: - description: "The algorithm used to encrypt fields for field level encryption represented - as an unsigned integer." - type: int - values: - kDeterministic: 1 - kRandom: 2 - - Fle2AlgorithmInt: - description: "The algorithm used to encrypt fields for field level encryption represented - as an unsigned integer." - type: int - values: - kUnindexed: 1 - kEquality: 2 - - Fle2PlaceholderType: - description: "The type of payload to generate from a placeholder" - type: int - values: - kInsert: 1 - kFind: 2 + structs: # Maps to the encrypt keyword in JSON Schema. @@ -117,59 +96,5 @@ structs: type: encryptSchemaKeyId optional: true - EncryptionPlaceholder: - description: "Implements Encryption BinData (subtype 6) sub-subtype 0, the intent-to-encrypt - mapping. Contains a value to encrypt and a description of how it should be encrypted." - strict: true - fields: - a: - description: "The encryption algorithm to be used." - type: FleAlgorithmInt - cpp_name: algorithm - ki: - description: "Used to query the key vault by _id. If omitted, ka must be specified." - type: uuid - cpp_name: keyId - optional: true - ka: - description: "Used to query the key vault by keyAltName. If omitted, - ki must be specified." - type: string - cpp_name: keyAltName - optional: true - v: - description: "value to encrypt" - type: IDLAnyType - cpp_name: value - FLE2EncryptionPlaceholder: - description: "Implements Encryption BinData (subtype 6) sub-subtype 0, the intent-to-encrypt - mapping. Contains a value to encrypt and a description of how it should be encrypted." - strict: true - fields: - t: - description: "The type number, determines what payload to replace the placeholder with" - type: Fle2PlaceholderType - cpp_name: type - a: - description: "The encryption algorithm to be used." - type: Fle2AlgorithmInt - cpp_name: algorithm - ki: - description: "IndexKeyId, Used to query the key vault by _id." - type: uuid - cpp_name: indexKeyId - ku: - description: "UserKeyId, Used to query the key vault by _id., - Typically same as IndexKeyId unless explicit encryption is used." - type: uuid - cpp_name: userKeyId - v: - description: "value to encrypt" - type: IDLAnyType - cpp_name: value - cm: - description: "FLE2 max contention counter" - type: long - cpp_name: maxContentionCounter diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index.h b/src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index.h index 0f2fe41a35c..0a613b23303 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_all_elem_match_from_index.h @@ -101,6 +101,12 @@ public: return _expression->getFilter(); } + void resetChild(size_t i, MatchExpression* other) { + tassert(6329407, "Out-of-bounds access to child of MatchExpression.", i < numChildren()); + _expression->resetFilter(other); + }; + + void acceptVisitor(MatchExpressionMutableVisitor* visitor) final { visitor->visit(this); } diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties.h b/src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties.h index a286212ee61..e95d0582d15 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_allowed_properties.h @@ -158,6 +158,16 @@ public: return _patternProperties[i - 1].second->getFilter(); } + virtual void resetChild(size_t i, MatchExpression* other) { + tassert(6329408, "Out-of-bounds access to child of MatchExpression.", i < numChildren()); + + if (i == 0) { + _otherwise->resetFilter(other); + } else { + _patternProperties[i - 1].second->resetFilter(other); + } + } + void acceptVisitor(MatchExpressionMutableVisitor* visitor) final { visitor->visit(this); } diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_eq.h b/src/mongo/db/matcher/schema/expression_internal_schema_eq.h index d7fd43a57ba..3f604294f60 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_eq.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_eq.h @@ -33,6 +33,7 @@ #include "mongo/bson/unordered_fields_bsonelement_comparator.h" #include "mongo/db/matcher/expression_leaf.h" +#include "mongo/util/assert_util.h" namespace mongo { @@ -70,6 +71,10 @@ public: MONGO_UNREACHABLE; } + void resetChild(size_t, MatchExpression*) override { + MONGO_UNREACHABLE; + } + void acceptVisitor(MatchExpressionMutableVisitor* visitor) final { visitor->visit(this); } diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_match_array_index.h b/src/mongo/db/matcher/schema/expression_internal_schema_match_array_index.h index 11126ae81d0..8fff1225bf3 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_match_array_index.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_match_array_index.h @@ -90,6 +90,11 @@ public: return _expression->getFilter(); } + void resetChild(size_t i, MatchExpression* other) final override { + tassert(6329409, "Out-of-bounds access to child of MatchExpression.", i < numChildren()); + _expression->resetFilter(other); + } + void acceptVisitor(MatchExpressionMutableVisitor* visitor) final { visitor->visit(this); } diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_num_array_items.h b/src/mongo/db/matcher/schema/expression_internal_schema_num_array_items.h index 8c6a4062d21..99ed79ec5d6 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_num_array_items.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_num_array_items.h @@ -33,6 +33,7 @@ #include "mongo/base/string_data.h" #include "mongo/db/matcher/expression_array.h" +#include "mongo/util/assert_util.h" namespace mongo { @@ -63,6 +64,10 @@ public: MONGO_UNREACHABLE; } + void resetChild(size_t i, MatchExpression* other) override { + MONGO_UNREACHABLE; + } + std::vector<std::unique_ptr<MatchExpression>>* getChildVector() final { return nullptr; } diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_num_properties.h b/src/mongo/db/matcher/schema/expression_internal_schema_num_properties.h index 563cfcda5a7..29fd4fc6145 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_num_properties.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_num_properties.h @@ -33,6 +33,7 @@ #include "mongo/base/string_data.h" #include "mongo/db/matcher/expression.h" +#include "mongo/util/assert_util.h" namespace mongo { @@ -60,6 +61,10 @@ public: MONGO_UNREACHABLE; } + void resetChild(size_t, MatchExpression*) override { + MONGO_UNREACHABLE; + } + std::vector<std::unique_ptr<MatchExpression>>* getChildVector() final { return nullptr; } diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_object_match.h b/src/mongo/db/matcher/schema/expression_internal_schema_object_match.h index 091d3af777f..93b6e1b765e 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_object_match.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_object_match.h @@ -68,6 +68,11 @@ public: return _sub.get(); } + void resetChild(size_t i, MatchExpression* other) final override { + tassert(6329410, "Out-of-bounds access to child of MatchExpression.", i < numChildren()); + _sub.reset(other); + } + MatchCategory getCategory() const final { return MatchCategory::kOther; } diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_root_doc_eq.h b/src/mongo/db/matcher/schema/expression_internal_schema_root_doc_eq.h index 47003cf630c..62dfb6d66a2 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_root_doc_eq.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_root_doc_eq.h @@ -33,6 +33,7 @@ #include "mongo/bson/unordered_fields_bsonobj_comparator.h" #include "mongo/db/matcher/expression.h" +#include "mongo/util/assert_util.h" namespace mongo { @@ -83,6 +84,10 @@ public: MONGO_UNREACHABLE; } + void resetChild(size_t i, MatchExpression*) final override { + MONGO_UNREACHABLE; + } + std::vector<std::unique_ptr<MatchExpression>>* getChildVector() final { return nullptr; } diff --git a/src/mongo/db/matcher/schema/expression_internal_schema_unique_items.h b/src/mongo/db/matcher/schema/expression_internal_schema_unique_items.h index ecd70d9ff8c..ddb86c89403 100644 --- a/src/mongo/db/matcher/schema/expression_internal_schema_unique_items.h +++ b/src/mongo/db/matcher/schema/expression_internal_schema_unique_items.h @@ -60,6 +60,10 @@ public: MONGO_UNREACHABLE; } + void resetChild(size_t i, MatchExpression*) final override { + MONGO_UNREACHABLE; + } + std::vector<std::unique_ptr<MatchExpression>>* getChildVector() final { return nullptr; } |