summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/query_planner_tree_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/query/query_planner_tree_test.cpp')
-rw-r--r--src/mongo/db/query/query_planner_tree_test.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/mongo/db/query/query_planner_tree_test.cpp b/src/mongo/db/query/query_planner_tree_test.cpp
index 5b7055dd720..7ea6d55dfb3 100644
--- a/src/mongo/db/query/query_planner_tree_test.cpp
+++ b/src/mongo/db/query/query_planner_tree_test.cpp
@@ -434,6 +434,39 @@ TEST_F(QueryPlannerTest, RootedOrOfAndDontCollapseDifferentBounds) {
"bounds: {c: [[3,3,true,true]], d: [[4,4,true,true]]}}}]}}}}");
}
+TEST_F(QueryPlannerTest, DontCrashTryingToPushToSingleChildIndexedOr1) {
+ FailPointEnableBlock failPoint("disableMatchExpressionOptimization");
+ addIndex(BSON("indexed" << 1));
+ runQuery(
+ fromjson("{ $and : [\n"
+ " { $and : [ { indexed : { $gt : 5 } },\n"
+ " { unindexed : 42 } ] },\n"
+ " { $or : [ { indexed: { $lt : 100 } } ] }\n"
+ " ] }"));
+
+ assertNumSolutions(3U);
+}
+
+TEST_F(QueryPlannerTest, DontCrashTryingToPushToSingleChildIndexedOr2) {
+ // Test that queries with single-child $and, $or do not crash when match-expression optimization
+ // is disabled. Normally these single-child nodes are eliminated, so when they are left in place
+ // it can confuse OR-pushdown optimization.
+ //
+ // Originally designed to reproduce SERVER-70597, which would only happen when the
+ // INDEX_INTERSECTION option is enabled.
+ FailPointEnableBlock failPoint("disableMatchExpressionOptimization");
+ addIndex(BSON("a" << 1 << "b" << 1));
+
+ params.options |= QueryPlannerParams::INDEX_INTERSECTION;
+ runQuery(
+ fromjson("{ $and : [\n"
+ " { $and : [ { a : 2 } ] },\n"
+ " { $or : [ { b : 3 } ] }\n"
+ " ] }"));
+
+ assertNumSolutions(2U);
+}
+
// SERVER-13960: properly handle $or with a mix of exact and inexact predicates.
TEST_F(QueryPlannerTest, OrInexactWithExact) {
addIndex(BSON("name" << 1));