summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrii Dobroshynskyi <andrii.dobroshynskyi@mongodb.com>2020-07-28 16:42:31 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-08-05 20:58:09 +0000
commit441f18826c8469f871c1055032cf49be69e6d314 (patch)
tree144f4e1e55af80b3012a4e179655ed86dd3e4d2c /src
parent6da20f433cc8a6ae47664f89085ee8873817d651 (diff)
downloadmongo-441f18826c8469f871c1055032cf49be69e6d314.tar.gz
SERVER-49839 Implement AlwaysFalse and AlwaysTrue match expressions in SBE
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/query/sbe_stage_builder_filter.cpp30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/mongo/db/query/sbe_stage_builder_filter.cpp b/src/mongo/db/query/sbe_stage_builder_filter.cpp
index 550dafaff31..3d9550279d0 100644
--- a/src/mongo/db/query/sbe_stage_builder_filter.cpp
+++ b/src/mongo/db/query/sbe_stage_builder_filter.cpp
@@ -508,6 +508,20 @@ void generateLogicalAnd(MatchExpressionVisitorContext* context, const AndMatchEx
}
/**
+ * Generates and pushes a constant boolean expression for either alwaysTrue or alwaysFalse.
+ */
+void generateAlwaysBoolean(MatchExpressionVisitorContext* context, bool value) {
+ context->predicateVars.push(context->slotIdGenerator->generate());
+ context->inputStage =
+ sbe::makeProjectStage(std::move(context->inputStage),
+ context->predicateVars.top(),
+ sbe::makeE<sbe::EConstant>(sbe::value::TypeTags::Boolean, value));
+
+ // Check if can bail out early from the $and predicate if this expression is part of branch.
+ checkForShortCircuitFromLogicalAnd(context);
+}
+
+/**
* A match expression pre-visitor used for maintaining nested logical expressions while traversing
* the match expression tree.
*/
@@ -515,12 +529,8 @@ class MatchExpressionPreVisitor final : public MatchExpressionConstVisitor {
public:
MatchExpressionPreVisitor(MatchExpressionVisitorContext* context) : _context(context) {}
- void visit(const AlwaysFalseMatchExpression* expr) final {
- unsupportedExpression(expr);
- }
- void visit(const AlwaysTrueMatchExpression* expr) final {
- unsupportedExpression(expr);
- }
+ void visit(const AlwaysFalseMatchExpression* expr) final {}
+ void visit(const AlwaysTrueMatchExpression* expr) final {}
void visit(const AndMatchExpression* expr) final {
_context->nestedLogicalExprs.push({expr, expr->numChildren()});
}
@@ -669,8 +679,12 @@ class MatchExpressionPostVisitor final : public MatchExpressionConstVisitor {
public:
MatchExpressionPostVisitor(MatchExpressionVisitorContext* context) : _context(context) {}
- void visit(const AlwaysFalseMatchExpression* expr) final {}
- void visit(const AlwaysTrueMatchExpression* expr) final {}
+ void visit(const AlwaysFalseMatchExpression* expr) final {
+ generateAlwaysBoolean(_context, false);
+ }
+ void visit(const AlwaysTrueMatchExpression* expr) final {
+ generateAlwaysBoolean(_context, true);
+ }
void visit(const AndMatchExpression* expr) final {
_context->nestedLogicalExprs.pop();
generateLogicalAnd(_context, expr);