From 7e7f7732145fd87888291661dcb40464fecf29eb Mon Sep 17 00:00:00 2001 From: Davis Haupt Date: Wed, 11 Jan 2023 14:59:07 +0000 Subject: SERVER-72312 Add lowering unittest for NestedLoopJoinNode --- src/mongo/db/exec/sbe/abt/abt_lower_test.cpp | 33 +++++++++ src/mongo/db/exec/sbe/stages/loop_join.cpp | 12 ++++ .../lower_nested_loop_join_node.txt | 79 ++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 src/mongo/db/test_output/exec/sbe/a_b_t_plan_generation/lower_nested_loop_join_node.txt (limited to 'src/mongo/db') 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 joins = {JoinType::Inner, JoinType::Left}; + for (auto& joinType : joins) { + auto child1 = createBindings( + {{"city", "proj0"}}, + _node(make( + FieldProjectionMap{{}, {ProjectionName{"scan0"}}, {}}, "collName", false)), + "scan0"); + auto child2 = createBindings( + {{"id", "proj1"}}, + _node(make( + FieldProjectionMap{{}, {ProjectionName{"scan1"}}, {}}, "otherColl", false)), + "scan1"); + + runNodeVariation( + ctx, + str::stream() << "Nested loop join with equality predicate (" + << JoinTypeEnum::toString[static_cast(joinType)] << " join)", + _node(make( + joinType, + ProjectionNameSet{"proj0"}, + _path(make( + make(Operations::Eq, make(ProjectionName{"proj1"})), + make(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 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 [{'': scan1}, otherColl] +| BindBlock: +| [scan1] +| Source [] +Evaluation [] +| BindBlock: +| [proj0] +| FunctionCall [getField] +| | Const ["city"] +| Variable [scan0] +PhysicalScan [{'': 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 [] @"" true false + right + [3] project [s4 = getField(s3, "id")] + [2] scan s3 none none none none none [] @"" 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 [{'': scan1}, otherColl] +| BindBlock: +| [scan1] +| Source [] +Evaluation [] +| BindBlock: +| [proj0] +| FunctionCall [getField] +| | Const ["city"] +| Variable [scan0] +PhysicalScan [{'': 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 [] @"" true false + right + [3] project [s4 = getField(s3, "id")] + [2] scan s3 none none none none none [] @"" true false + -- cgit v1.2.1