summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavis Haupt <davis.haupt@mongodb.com>2023-01-11 14:59:07 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-01-11 16:00:53 +0000
commit7e7f7732145fd87888291661dcb40464fecf29eb (patch)
tree3ea0f187661aa3bae8cb65a5a12431e2fb67ae3d /src
parent9bd31b4fb9586a9a3493fa7332be64e84d360dd1 (diff)
downloadmongo-7e7f7732145fd87888291661dcb40464fecf29eb.tar.gz
SERVER-72312 Add lowering unittest for NestedLoopJoinNode
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/exec/sbe/abt/abt_lower_test.cpp33
-rw-r--r--src/mongo/db/exec/sbe/stages/loop_join.cpp12
-rw-r--r--src/mongo/db/test_output/exec/sbe/a_b_t_plan_generation/lower_nested_loop_join_node.txt79
3 files changed, 124 insertions, 0 deletions
diff --git a/src/mongo/db/exec/sbe/abt/abt_lower_test.cpp b/src/mongo/db/exec/sbe/abt/abt_lower_test.cpp
index 206a7f93502..74a094a3470 100644
--- a/src/mongo/db/exec/sbe/abt/abt_lower_test.cpp
+++ b/src/mongo/db/exec/sbe/abt/abt_lower_test.cpp
@@ -482,6 +482,39 @@ TEST_F(ABTPlanGeneration, LowerMergeJoinNode) {
}
}
+TEST_F(ABTPlanGeneration, LowerNestedLoopJoinNode) {
+ GoldenTestContext ctx(&goldenTestConfig);
+ ctx.printTestHeader(GoldenTestContext::HeaderFormat::Text);
+
+ // Run a variation for both supported join types.
+ std::vector<JoinType> joins = {JoinType::Inner, JoinType::Left};
+ for (auto& joinType : joins) {
+ auto child1 = createBindings(
+ {{"city", "proj0"}},
+ _node(make<PhysicalScanNode>(
+ FieldProjectionMap{{}, {ProjectionName{"scan0"}}, {}}, "collName", false)),
+ "scan0");
+ auto child2 = createBindings(
+ {{"id", "proj1"}},
+ _node(make<PhysicalScanNode>(
+ FieldProjectionMap{{}, {ProjectionName{"scan1"}}, {}}, "otherColl", false)),
+ "scan1");
+
+ runNodeVariation(
+ ctx,
+ str::stream() << "Nested loop join with equality predicate ("
+ << JoinTypeEnum::toString[static_cast<int>(joinType)] << " join)",
+ _node(make<NestedLoopJoinNode>(
+ joinType,
+ ProjectionNameSet{"proj0"},
+ _path(make<EvalFilter>(
+ make<PathCompare>(Operations::Eq, make<Variable>(ProjectionName{"proj1"})),
+ make<Variable>(ProjectionName{"proj0"}))),
+ std::move(child1),
+ std::move(child2))));
+ }
+}
+
TEST_F(ABTPlanGeneration, LowerPhysicalScanNode) {
GoldenTestContext ctx(&goldenTestConfig);
ctx.printTestHeader(GoldenTestContext::HeaderFormat::Text);
diff --git a/src/mongo/db/exec/sbe/stages/loop_join.cpp b/src/mongo/db/exec/sbe/stages/loop_join.cpp
index 123faa7daf5..8bff1012bca 100644
--- a/src/mongo/db/exec/sbe/stages/loop_join.cpp
+++ b/src/mongo/db/exec/sbe/stages/loop_join.cpp
@@ -244,6 +244,18 @@ const SpecificStats* LoopJoinStage::getSpecificStats() const {
std::vector<DebugPrinter::Block> LoopJoinStage::debugPrint() const {
auto ret = PlanStage::debugPrint();
+ switch (_joinType) {
+ case JoinType::Inner:
+ ret.emplace_back(DebugPrinter::Block("inner"));
+ break;
+ case JoinType::Left:
+ ret.emplace_back(DebugPrinter::Block("left"));
+ break;
+ case JoinType::Right:
+ ret.emplace_back(DebugPrinter::Block("right"));
+ break;
+ }
+
ret.emplace_back(DebugPrinter::Block("[`"));
for (size_t idx = 0; idx < _outerProjects.size(); ++idx) {
if (idx) {
diff --git a/src/mongo/db/test_output/exec/sbe/a_b_t_plan_generation/lower_nested_loop_join_node.txt b/src/mongo/db/test_output/exec/sbe/a_b_t_plan_generation/lower_nested_loop_join_node.txt
new file mode 100644
index 00000000000..29764e12e1c
--- /dev/null
+++ b/src/mongo/db/test_output/exec/sbe/a_b_t_plan_generation/lower_nested_loop_join_node.txt
@@ -0,0 +1,79 @@
+# Golden test output of ABTPlanGeneration/LowerNestedLoopJoinNode
+
+==== VARIATION: Nested loop join with equality predicate (Inner join) ====
+-- INPUT:
+NestedLoopJoin [joinType: Inner, {proj0}]
+| | BinaryOp [FillEmpty]
+| | | Const [false]
+| | BinaryOp [Eq]
+| | | Variable [proj1]
+| | Variable [proj0]
+| Evaluation []
+| | BindBlock:
+| | [proj1]
+| | FunctionCall [getField]
+| | | Const ["id"]
+| | Variable [scan1]
+| PhysicalScan [{'<root>': scan1}, otherColl]
+| BindBlock:
+| [scan1]
+| Source []
+Evaluation []
+| BindBlock:
+| [proj0]
+| FunctionCall [getField]
+| | Const ["city"]
+| Variable [scan0]
+PhysicalScan [{'<root>': scan0}, collName]
+ BindBlock:
+ [scan0]
+ Source []
+
+-- OUTPUT:
+[4] nlj inner [] [s2] {((s2 == s4) ?: false)}
+ left
+ [1] project [s2 = getField(s1, "city")]
+ [0] scan s1 none none none none none [] @"<collUUID>" true false
+ right
+ [3] project [s4 = getField(s3, "id")]
+ [2] scan s3 none none none none none [] @"<collUUID>" true false
+
+
+==== VARIATION: Nested loop join with equality predicate (Left join) ====
+-- INPUT:
+NestedLoopJoin [joinType: Left, {proj0}]
+| | BinaryOp [FillEmpty]
+| | | Const [false]
+| | BinaryOp [Eq]
+| | | Variable [proj1]
+| | Variable [proj0]
+| Evaluation []
+| | BindBlock:
+| | [proj1]
+| | FunctionCall [getField]
+| | | Const ["id"]
+| | Variable [scan1]
+| PhysicalScan [{'<root>': scan1}, otherColl]
+| BindBlock:
+| [scan1]
+| Source []
+Evaluation []
+| BindBlock:
+| [proj0]
+| FunctionCall [getField]
+| | Const ["city"]
+| Variable [scan0]
+PhysicalScan [{'<root>': scan0}, collName]
+ BindBlock:
+ [scan0]
+ Source []
+
+-- OUTPUT:
+[4] nlj left [] [s2] {((s2 == s4) ?: false)}
+ left
+ [1] project [s2 = getField(s1, "city")]
+ [0] scan s1 none none none none none [] @"<collUUID>" true false
+ right
+ [3] project [s4 = getField(s3, "id")]
+ [2] scan s3 none none none none none [] @"<collUUID>" true false
+