diff options
author | Nikita Lapkov <nikita.lapkov@mongodb.com> | 2021-02-25 12:13:12 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-03-01 19:25:51 +0000 |
commit | f7d172d0decc6128b6ce497357bbf0ff0e676355 (patch) | |
tree | 018d07884f5a7e876d84aedab69b6270183f2197 /src/mongo/db/query/sbe_stage_builder_filter.cpp | |
parent | 4b95014f05755a197d81f97879a24c9a6e5c535d (diff) | |
download | mongo-f7d172d0decc6128b6ce497357bbf0ff0e676355.tar.gz |
SERVER-54493 Support BSONType::RegEx values in $regex match expression in SBE
Diffstat (limited to 'src/mongo/db/query/sbe_stage_builder_filter.cpp')
-rw-r--r-- | src/mongo/db/query/sbe_stage_builder_filter.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/mongo/db/query/sbe_stage_builder_filter.cpp b/src/mongo/db/query/sbe_stage_builder_filter.cpp index 8f5d9b36b55..6b44d54063b 100644 --- a/src/mongo/db/query/sbe_stage_builder_filter.cpp +++ b/src/mongo/db/query/sbe_stage_builder_filter.cpp @@ -1541,16 +1541,24 @@ public: void visit(const RegexMatchExpression* expr) final { auto makePredicate = [expr](sbe::value::SlotId inputSlot, EvalStage inputStage) -> EvalExprStagePair { - auto [regexTag, regexVal] = + auto [bsonRegexTag, bsonRegexVal] = + sbe::value::makeNewBsonRegex(expr->getString(), expr->getFlags()); + auto [compiledRegexTag, compiledRegexVal] = sbe::value::makeNewPcreRegex(expr->getString(), expr->getFlags()); - // TODO: In the future, this needs to account for the fact that the regex match - // expression matches strings, but also matches stored regexes. For example, - // {$match: {a: /foo/}} matches the document {a: /foo/} in addition to {a: "foobar"}. - return {makeFillEmptyFalse(sbe::makeE<sbe::EFunction>( - "regexMatch", - sbe::makeEs(sbe::makeE<sbe::EConstant>(regexTag, regexVal), - sbe::makeE<sbe::EVariable>(inputSlot)))), - std::move(inputStage)}; + // TODO SERVER-54837: Support BSONType::Symbol once it is added to SBE. + sbe::EVariable inputVar{inputSlot}; + auto resultExpr = makeBinaryOp( + sbe::EPrimBinary::logicOr, + makeFillEmptyFalse( + makeBinaryOp(sbe::EPrimBinary::eq, + inputVar.clone(), + sbe::makeE<sbe::EConstant>(bsonRegexTag, bsonRegexVal))), + makeFillEmptyFalse( + makeFunction("regexMatch", + sbe::makeE<sbe::EConstant>(compiledRegexTag, compiledRegexVal), + inputVar.clone()))); + + return {std::move(resultExpr), std::move(inputStage)}; }; generatePredicate(_context, expr->fieldRef(), std::move(makePredicate)); |