From 9e0e128dd5d5007424642777a08ae292f88970c1 Mon Sep 17 00:00:00 2001 From: yibin Date: Wed, 19 Apr 2023 15:21:19 +0800 Subject: [PATCH] Rename left to leftouter, right to rightouter for join kind enum (#7319) close pingcap/tiflash#7309 --- .../HashJoinBuildBlockInputStream.cpp | 20 ++--- dbms/src/Debug/MockExecutor/JoinBinder.cpp | 4 +- .../Coprocessor/DAGQueryBlockInterpreter.cpp | 2 +- .../Coprocessor/JoinInterpreterHelper.cpp | 38 ++++---- .../Flash/Coprocessor/JoinInterpreterHelper.h | 18 ++-- .../gtest_join_get_kind_and_build_index.cpp | 40 ++++----- dbms/src/Flash/Planner/Plans/PhysicalJoin.cpp | 2 +- dbms/src/Flash/tests/gtest_join_executor.cpp | 4 +- dbms/src/Interpreters/ExpressionActions.cpp | 2 +- dbms/src/Interpreters/ExpressionAnalyzer.cpp | 2 +- .../Interpreters/InterpreterSelectQuery.cpp | 2 +- dbms/src/Interpreters/Join.cpp | 90 +++++++++---------- dbms/src/Interpreters/Join.h | 2 +- dbms/src/Interpreters/JoinPartition.cpp | 46 +++++----- dbms/src/Interpreters/JoinUtils.cpp | 6 +- dbms/src/Interpreters/JoinUtils.h | 32 +++---- .../Interpreters/NullAwareSemiJoinHelper.cpp | 10 +-- .../Interpreters/NullAwareSemiJoinHelper.h | 18 ++-- dbms/src/Parsers/ASTTablesInSelectQuery.cpp | 4 +- dbms/src/Parsers/ASTTablesInSelectQuery.h | 20 ++--- .../src/Parsers/ParserTablesInSelectQuery.cpp | 8 +- 21 files changed, 185 insertions(+), 185 deletions(-) diff --git a/dbms/src/DataStreams/HashJoinBuildBlockInputStream.cpp b/dbms/src/DataStreams/HashJoinBuildBlockInputStream.cpp index 61999b154b9..619c71c1d50 100644 --- a/dbms/src/DataStreams/HashJoinBuildBlockInputStream.cpp +++ b/dbms/src/DataStreams/HashJoinBuildBlockInputStream.cpp @@ -42,22 +42,22 @@ void HashJoinBuildBlockInputStream::appendInfo(FmtBuffer & buffer) const { static const std::unordered_map join_type_map{ {ASTTableJoin::Kind::Inner, "Inner"}, - {ASTTableJoin::Kind::Left, "Left"}, - {ASTTableJoin::Kind::Right, "Right"}, + {ASTTableJoin::Kind::LeftOuter, "Left"}, + {ASTTableJoin::Kind::RightOuter, "Right"}, {ASTTableJoin::Kind::Full, "Full"}, {ASTTableJoin::Kind::Cross, "Cross"}, {ASTTableJoin::Kind::Comma, "Comma"}, {ASTTableJoin::Kind::Anti, "Anti"}, - {ASTTableJoin::Kind::LeftSemi, "Left_Semi"}, - {ASTTableJoin::Kind::LeftAnti, "Left_Anti"}, - {ASTTableJoin::Kind::Cross_Left, "Cross_Left"}, - {ASTTableJoin::Kind::Cross_Right, "Cross_Right"}, + {ASTTableJoin::Kind::LeftOuterSemi, "Left_Semi"}, + {ASTTableJoin::Kind::LeftOuterAnti, "Left_Anti"}, + {ASTTableJoin::Kind::Cross_LeftOuter, "Cross_Left"}, + {ASTTableJoin::Kind::Cross_RightOuter, "Cross_Right"}, {ASTTableJoin::Kind::Cross_Anti, "Cross_Anti"}, - {ASTTableJoin::Kind::Cross_LeftSemi, "Cross_LeftSemi"}, - {ASTTableJoin::Kind::Cross_LeftAnti, "Cross_LeftAnti"}, + {ASTTableJoin::Kind::Cross_LeftOuterSemi, "Cross_LeftSemi"}, + {ASTTableJoin::Kind::Cross_LeftOuterAnti, "Cross_LeftAnti"}, {ASTTableJoin::Kind::NullAware_Anti, "NullAware_Anti"}, - {ASTTableJoin::Kind::NullAware_LeftSemi, "NullAware_LeftSemi"}, - {ASTTableJoin::Kind::NullAware_LeftAnti, "NullAware_LeftAnti"}, + {ASTTableJoin::Kind::NullAware_LeftOuterSemi, "NullAware_LeftSemi"}, + {ASTTableJoin::Kind::NullAware_LeftOuterAnti, "NullAware_LeftAnti"}, {ASTTableJoin::Kind::RightSemi, "RightSemi"}, {ASTTableJoin::Kind::RightAnti, "RightAnti"}, }; diff --git a/dbms/src/Debug/MockExecutor/JoinBinder.cpp b/dbms/src/Debug/MockExecutor/JoinBinder.cpp index cd5e6552201..8621bf9792b 100644 --- a/dbms/src/Debug/MockExecutor/JoinBinder.cpp +++ b/dbms/src/Debug/MockExecutor/JoinBinder.cpp @@ -323,10 +323,10 @@ ExecutorBinderPtr compileJoin(size_t & executor_index, ExecutorBinderPtr left, E case ASTTableJoin::Kind::Inner: tp = tipb::JoinType::TypeInnerJoin; break; - case ASTTableJoin::Kind::Left: + case ASTTableJoin::Kind::LeftOuter: tp = tipb::JoinType::TypeLeftOuterJoin; break; - case ASTTableJoin::Kind::Right: + case ASTTableJoin::Kind::RightOuter: tp = tipb::JoinType::TypeRightOuterJoin; break; default: diff --git a/dbms/src/Flash/Coprocessor/DAGQueryBlockInterpreter.cpp b/dbms/src/Flash/Coprocessor/DAGQueryBlockInterpreter.cpp index 7ce1cb7a862..7a488c9279d 100644 --- a/dbms/src/Flash/Coprocessor/DAGQueryBlockInterpreter.cpp +++ b/dbms/src/Flash/Coprocessor/DAGQueryBlockInterpreter.cpp @@ -240,7 +240,7 @@ void DAGQueryBlockInterpreter::handleJoin(const tipb::Join & join, DAGPipeline & NamesAndTypes join_output_columns = tiflash_join.genJoinOutputColumns(left_input_header, right_input_header, match_helper_name); /// add necessary transformation if the join key is an expression - bool is_tiflash_right_join = tiflash_join.isTiFlashRightJoin(); + bool is_tiflash_right_join = tiflash_join.isTiFlashRightOuterJoin(); JoinNonEqualConditions join_non_equal_conditions; // prepare probe side diff --git a/dbms/src/Flash/Coprocessor/JoinInterpreterHelper.cpp b/dbms/src/Flash/Coprocessor/JoinInterpreterHelper.cpp index 46e992ea26d..6749ebf474d 100644 --- a/dbms/src/Flash/Coprocessor/JoinInterpreterHelper.cpp +++ b/dbms/src/Flash/Coprocessor/JoinInterpreterHelper.cpp @@ -42,24 +42,24 @@ std::pair getJoinKindAndBuildSideIndex(tipb::JoinTyp { static const std::unordered_map equal_join_type_map{ {tipb::JoinType::TypeInnerJoin, ASTTableJoin::Kind::Inner}, - {tipb::JoinType::TypeLeftOuterJoin, ASTTableJoin::Kind::Left}, - {tipb::JoinType::TypeRightOuterJoin, ASTTableJoin::Kind::Right}, + {tipb::JoinType::TypeLeftOuterJoin, ASTTableJoin::Kind::LeftOuter}, + {tipb::JoinType::TypeRightOuterJoin, ASTTableJoin::Kind::RightOuter}, {tipb::JoinType::TypeSemiJoin, ASTTableJoin::Kind::Inner}, {tipb::JoinType::TypeAntiSemiJoin, ASTTableJoin::Kind::Anti}, - {tipb::JoinType::TypeLeftOuterSemiJoin, ASTTableJoin::Kind::LeftSemi}, - {tipb::JoinType::TypeAntiLeftOuterSemiJoin, ASTTableJoin::Kind::LeftAnti}}; + {tipb::JoinType::TypeLeftOuterSemiJoin, ASTTableJoin::Kind::LeftOuterSemi}, + {tipb::JoinType::TypeAntiLeftOuterSemiJoin, ASTTableJoin::Kind::LeftOuterAnti}}; static const std::unordered_map cartesian_join_type_map{ {tipb::JoinType::TypeInnerJoin, ASTTableJoin::Kind::Cross}, - {tipb::JoinType::TypeLeftOuterJoin, ASTTableJoin::Kind::Cross_Left}, - {tipb::JoinType::TypeRightOuterJoin, ASTTableJoin::Kind::Cross_Right}, + {tipb::JoinType::TypeLeftOuterJoin, ASTTableJoin::Kind::Cross_LeftOuter}, + {tipb::JoinType::TypeRightOuterJoin, ASTTableJoin::Kind::Cross_RightOuter}, {tipb::JoinType::TypeSemiJoin, ASTTableJoin::Kind::Cross}, {tipb::JoinType::TypeAntiSemiJoin, ASTTableJoin::Kind::Cross_Anti}, - {tipb::JoinType::TypeLeftOuterSemiJoin, ASTTableJoin::Kind::Cross_LeftSemi}, - {tipb::JoinType::TypeAntiLeftOuterSemiJoin, ASTTableJoin::Kind::Cross_LeftAnti}}; + {tipb::JoinType::TypeLeftOuterSemiJoin, ASTTableJoin::Kind::Cross_LeftOuterSemi}, + {tipb::JoinType::TypeAntiLeftOuterSemiJoin, ASTTableJoin::Kind::Cross_LeftOuterAnti}}; static const std::unordered_map null_aware_join_type_map{ {tipb::JoinType::TypeAntiSemiJoin, ASTTableJoin::Kind::NullAware_Anti}, - {tipb::JoinType::TypeLeftOuterSemiJoin, ASTTableJoin::Kind::NullAware_LeftSemi}, - {tipb::JoinType::TypeAntiLeftOuterSemiJoin, ASTTableJoin::Kind::NullAware_LeftAnti}}; + {tipb::JoinType::TypeLeftOuterSemiJoin, ASTTableJoin::Kind::NullAware_LeftOuterSemi}, + {tipb::JoinType::TypeAntiLeftOuterSemiJoin, ASTTableJoin::Kind::NullAware_LeftOuterAnti}}; const auto & join_type_map = [is_null_aware, join_keys_size]() { if (is_null_aware) @@ -92,10 +92,10 @@ std::pair getJoinKindAndBuildSideIndex(tipb::JoinTyp size_t build_side_index = 0; switch (kind) { - case ASTTableJoin::Kind::Cross_Right: + case ASTTableJoin::Kind::Cross_RightOuter: build_side_index = 0; break; - case ASTTableJoin::Kind::Cross_Left: + case ASTTableJoin::Kind::Cross_LeftOuter: build_side_index = 1; break; default: @@ -116,14 +116,14 @@ std::pair getJoinKindAndBuildSideIndex(tipb::JoinTyp if (tipb_join_type == tipb::JoinType::TypeAntiSemiJoin) kind = ASTTableJoin::Kind::RightAnti; break; - case ASTTableJoin::Kind::Left: - kind = ASTTableJoin::Kind::Right; + case ASTTableJoin::Kind::LeftOuter: + kind = ASTTableJoin::Kind::RightOuter; break; - case ASTTableJoin::Kind::Right: - kind = ASTTableJoin::Kind::Left; + case ASTTableJoin::Kind::RightOuter: + kind = ASTTableJoin::Kind::LeftOuter; break; - case ASTTableJoin::Kind::Cross_Right: - kind = ASTTableJoin::Kind::Cross_Left; + case ASTTableJoin::Kind::Cross_RightOuter: + kind = ASTTableJoin::Kind::Cross_LeftOuter; break; default:; // just `default`, for other kinds, don't need to change kind. } @@ -216,7 +216,7 @@ TiFlashJoin::TiFlashJoin(const tipb::Join & join_, bool is_test) // NOLINT(cppco String TiFlashJoin::genMatchHelperName(const Block & header1, const Block & header2) const { - if (!isLeftSemiFamily()) + if (!isLeftOuterSemiFamily()) { return ""; } diff --git a/dbms/src/Flash/Coprocessor/JoinInterpreterHelper.h b/dbms/src/Flash/Coprocessor/JoinInterpreterHelper.h index 13c41dd4c35..16704abb927 100644 --- a/dbms/src/Flash/Coprocessor/JoinInterpreterHelper.h +++ b/dbms/src/Flash/Coprocessor/JoinInterpreterHelper.h @@ -92,9 +92,9 @@ struct JoinNonEqualConditions /// Validate this JoinNonEqualConditions and return error message if any. String validate(ASTTableJoin::Kind kind) const { - if (unlikely(!left_filter_column.empty() && !isLeftJoin(kind))) + if (unlikely(!left_filter_column.empty() && !isLeftOuterJoin(kind))) return "non left join with left conditions"; - if (unlikely(!right_filter_column.empty() && !isRightJoin(kind))) + if (unlikely(!right_filter_column.empty() && !isRightOuterJoin(kind))) return "non right join with right conditions"; if unlikely ((!other_cond_name.empty() || !other_eq_cond_from_in_name.empty()) && other_cond_expr == nullptr) @@ -130,10 +130,10 @@ struct TiFlashJoin ASTTableJoin::Strictness strictness; - /// (cartesian) (anti) left semi join. - bool isLeftSemiFamily() const { return join.join_type() == tipb::JoinType::TypeLeftOuterSemiJoin || join.join_type() == tipb::JoinType::TypeAntiLeftOuterSemiJoin; } + /// (cartesian) (anti) left outer semi join. + bool isLeftOuterSemiFamily() const { return join.join_type() == tipb::JoinType::TypeLeftOuterSemiJoin || join.join_type() == tipb::JoinType::TypeAntiLeftOuterSemiJoin; } - bool isSemiJoin() const { return join.join_type() == tipb::JoinType::TypeSemiJoin || join.join_type() == tipb::JoinType::TypeAntiSemiJoin || isLeftSemiFamily(); } + bool isSemiJoin() const { return join.join_type() == tipb::JoinType::TypeSemiJoin || join.join_type() == tipb::JoinType::TypeAntiSemiJoin || isLeftOuterSemiFamily(); } const google::protobuf::RepeatedPtrField & getBuildJoinKeys() const { @@ -155,12 +155,12 @@ struct TiFlashJoin return build_side_index == 0 ? join.right_conditions() : join.left_conditions(); } - bool isTiFlashLeftJoin() const { return kind == ASTTableJoin::Kind::Left || kind == ASTTableJoin::Kind::Cross_Left; } + bool isTiFlashLeftOuterJoin() const { return kind == ASTTableJoin::Kind::LeftOuter || kind == ASTTableJoin::Kind::Cross_LeftOuter; } - /// Cross_Right join will be converted to Cross_Left join, so no need to check Cross_Right - bool isTiFlashRightJoin() const { return kind == ASTTableJoin::Kind::Right; } + /// Cross_RightOuter join will be converted to Cross_LeftOuter join, so no need to check Cross_RightOuter + bool isTiFlashRightOuterJoin() const { return kind == ASTTableJoin::Kind::RightOuter; } - /// return a name that is unique in header1 and header2 for left semi family join, + /// return a name that is unique in header1 and header2 for left outer semi family join, /// return "" for everything else. String genMatchHelperName(const Block & header1, const Block & header2) const; diff --git a/dbms/src/Flash/Coprocessor/tests/gtest_join_get_kind_and_build_index.cpp b/dbms/src/Flash/Coprocessor/tests/gtest_join_get_kind_and_build_index.cpp index b3b701f73d4..2fe3492fdee 100644 --- a/dbms/src/Flash/Coprocessor/tests/gtest_join_get_kind_and_build_index.cpp +++ b/dbms/src/Flash/Coprocessor/tests/gtest_join_get_kind_and_build_index.cpp @@ -36,10 +36,10 @@ TEST(JoinKindAndBuildIndexTestRunner, TestNullAwareJoins) ASSERT_TRUE(result.first == ASTTableJoin::Kind::NullAware_Anti && result.second == 1); result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeLeftOuterSemiJoin, 1, true, 1); - ASSERT_TRUE(result.first == ASTTableJoin::Kind::NullAware_LeftSemi && result.second == 1); + ASSERT_TRUE(result.first == ASTTableJoin::Kind::NullAware_LeftOuterSemi && result.second == 1); result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeAntiLeftOuterSemiJoin, 1, true, 1); - ASSERT_TRUE(result.first == ASTTableJoin::Kind::NullAware_LeftAnti && result.second == 1); + ASSERT_TRUE(result.first == ASTTableJoin::Kind::NullAware_LeftOuterAnti && result.second == 1); /// NullAware join, expect join keys > 0 try @@ -55,9 +55,9 @@ TEST(JoinKindAndBuildIndexTestRunner, TestNullAwareJoins) result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeAntiSemiJoin, 0, true, 1); ASSERT_TRUE(result.first == ASTTableJoin::Kind::NullAware_Anti && result.second == 0); result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeLeftOuterSemiJoin, 0, true, 1); - ASSERT_TRUE(result.first == ASTTableJoin::Kind::NullAware_LeftSemi && result.second == 0); + ASSERT_TRUE(result.first == ASTTableJoin::Kind::NullAware_LeftOuterSemi && result.second == 0); result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeAntiLeftOuterSemiJoin, 0, true, 1); - ASSERT_TRUE(result.first == ASTTableJoin::Kind::NullAware_LeftAnti && result.second == 0); + ASSERT_TRUE(result.first == ASTTableJoin::Kind::NullAware_LeftOuterAnti && result.second == 0); } TEST(JoinKindAndBuildIndexTestRunner, TestCrossJoins) @@ -70,15 +70,15 @@ TEST(JoinKindAndBuildIndexTestRunner, TestCrossJoins) /// Cross LeftOuterJoin, uses right table as build side only result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeLeftOuterJoin, 1, false, 0); - ASSERT_TRUE(result.first == ASTTableJoin::Kind::Cross_Left && result.second == 1); + ASSERT_TRUE(result.first == ASTTableJoin::Kind::Cross_LeftOuter && result.second == 1); result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeLeftOuterJoin, 0, false, 0); - ASSERT_TRUE(result.first == ASTTableJoin::Kind::Cross_Left && result.second == 1); + ASSERT_TRUE(result.first == ASTTableJoin::Kind::Cross_LeftOuter && result.second == 1); /// Cross RightOuterJoin, uses left table as build side only result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeRightOuterJoin, 0, false, 0); - ASSERT_TRUE(result.first == ASTTableJoin::Kind::Cross_Left && result.second == 0); + ASSERT_TRUE(result.first == ASTTableJoin::Kind::Cross_LeftOuter && result.second == 0); result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeRightOuterJoin, 1, false, 0); - ASSERT_TRUE(result.first == ASTTableJoin::Kind::Cross_Left && result.second == 0); + ASSERT_TRUE(result.first == ASTTableJoin::Kind::Cross_LeftOuter && result.second == 0); /// Cross Semi/Anti, uses right table as build side only result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeSemiJoin, 1, false, 0); @@ -92,13 +92,13 @@ TEST(JoinKindAndBuildIndexTestRunner, TestCrossJoins) /// Cross LeftOuter Semi/Anti, uses right table as build side only result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeLeftOuterSemiJoin, 1, false, 0); - ASSERT_TRUE(result.first == ASTTableJoin::Kind::Cross_LeftSemi && result.second == 1); + ASSERT_TRUE(result.first == ASTTableJoin::Kind::Cross_LeftOuterSemi && result.second == 1); result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeLeftOuterSemiJoin, 0, false, 0); - ASSERT_TRUE(result.first == ASTTableJoin::Kind::Cross_LeftSemi && result.second == 0); + ASSERT_TRUE(result.first == ASTTableJoin::Kind::Cross_LeftOuterSemi && result.second == 0); result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeAntiLeftOuterSemiJoin, 1, false, 0); - ASSERT_TRUE(result.first == ASTTableJoin::Kind::Cross_LeftAnti && result.second == 1); + ASSERT_TRUE(result.first == ASTTableJoin::Kind::Cross_LeftOuterAnti && result.second == 1); result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeAntiLeftOuterSemiJoin, 0, false, 0); - ASSERT_TRUE(result.first == ASTTableJoin::Kind::Cross_LeftAnti && result.second == 0); + ASSERT_TRUE(result.first == ASTTableJoin::Kind::Cross_LeftOuterAnti && result.second == 0); } TEST(JoinKindAndBuildIndexTestRunner, TestEqualJoins) @@ -111,15 +111,15 @@ TEST(JoinKindAndBuildIndexTestRunner, TestEqualJoins) /// LeftOuterJoin result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeLeftOuterJoin, 1, false, 1); - ASSERT_TRUE(result.first == ASTTableJoin::Kind::Left && result.second == 1); + ASSERT_TRUE(result.first == ASTTableJoin::Kind::LeftOuter && result.second == 1); result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeLeftOuterJoin, 0, false, 1); - ASSERT_TRUE(result.first == ASTTableJoin::Kind::Right && result.second == 0); + ASSERT_TRUE(result.first == ASTTableJoin::Kind::RightOuter && result.second == 0); /// RightOuterJoin result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeRightOuterJoin, 0, false, 1); - ASSERT_TRUE(result.first == ASTTableJoin::Kind::Left && result.second == 0); + ASSERT_TRUE(result.first == ASTTableJoin::Kind::LeftOuter && result.second == 0); result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeRightOuterJoin, 1, false, 1); - ASSERT_TRUE(result.first == ASTTableJoin::Kind::Right && result.second == 1); + ASSERT_TRUE(result.first == ASTTableJoin::Kind::RightOuter && result.second == 1); /// Semi/Anti result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeSemiJoin, 1, false, 1); @@ -133,13 +133,13 @@ TEST(JoinKindAndBuildIndexTestRunner, TestEqualJoins) /// LeftOuter Semi/Anti result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeLeftOuterSemiJoin, 1, false, 1); - ASSERT_TRUE(result.first == ASTTableJoin::Kind::LeftSemi && result.second == 1); + ASSERT_TRUE(result.first == ASTTableJoin::Kind::LeftOuterSemi && result.second == 1); result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeLeftOuterSemiJoin, 0, false, 1); - ASSERT_TRUE(result.first == ASTTableJoin::Kind::LeftSemi && result.second == 0); + ASSERT_TRUE(result.first == ASTTableJoin::Kind::LeftOuterSemi && result.second == 0); result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeAntiLeftOuterSemiJoin, 1, false, 1); - ASSERT_TRUE(result.first == ASTTableJoin::Kind::LeftAnti && result.second == 1); + ASSERT_TRUE(result.first == ASTTableJoin::Kind::LeftOuterAnti && result.second == 1); result = JoinInterpreterHelper::getJoinKindAndBuildSideIndex(tipb::JoinType::TypeAntiLeftOuterSemiJoin, 0, false, 1); - ASSERT_TRUE(result.first == ASTTableJoin::Kind::LeftAnti && result.second == 0); + ASSERT_TRUE(result.first == ASTTableJoin::Kind::LeftOuterAnti && result.second == 0); } } // namespace tests diff --git a/dbms/src/Flash/Planner/Plans/PhysicalJoin.cpp b/dbms/src/Flash/Planner/Plans/PhysicalJoin.cpp index 9518643d152..5cb9b2faeb4 100644 --- a/dbms/src/Flash/Planner/Plans/PhysicalJoin.cpp +++ b/dbms/src/Flash/Planner/Plans/PhysicalJoin.cpp @@ -87,7 +87,7 @@ PhysicalPlanNodePtr PhysicalJoin::build( /// add necessary transformation if the join key is an expression - bool is_tiflash_right_join = tiflash_join.isTiFlashRightJoin(); + bool is_tiflash_right_join = tiflash_join.isTiFlashRightOuterJoin(); JoinNonEqualConditions join_non_equal_conditions; // prepare probe side diff --git a/dbms/src/Flash/tests/gtest_join_executor.cpp b/dbms/src/Flash/tests/gtest_join_executor.cpp index 02c49a8325f..a9538b6308d 100644 --- a/dbms/src/Flash/tests/gtest_join_executor.cpp +++ b/dbms/src/Flash/tests/gtest_join_executor.cpp @@ -675,13 +675,13 @@ try request = context.scan("null_test", "t") .join(context.scan("null_test", "null_table"), tipb::JoinType::TypeLeftOuterSemiJoin, {}, {}, {}, {cond}, {}) .build(context); - // the 4th col is left semi helper col. + // the 4th col is left outer semi helper col. executeAndAssertColumnsEqual(request, {toNullableVec({1, 2, 3, 4, 5, 6, 7, 8, 9, 0}), toNullableVec({1, 1, 1, 1, 1, 1, 1, 2, 2, 2}), toNullableVec({1, 1, 1, 1, 1, 2, 2, 2, 2, 2}), toNullableVec({0, 0, 0, 0, 0, 0, 0, 0, 0, 0})}); request = context.scan("null_test", "t") .join(context.scan("null_test", "null_table"), tipb::JoinType::TypeAntiLeftOuterSemiJoin, {}, {}, {}, {cond}, {}) .build(context); - // the 4th col is left semi helper col. + // the 4th col is left outer semi helper col. executeAndAssertColumnsEqual(request, {toNullableVec({1, 2, 3, 4, 5, 6, 7, 8, 9, 0}), toNullableVec({1, 1, 1, 1, 1, 1, 1, 2, 2, 2}), toNullableVec({1, 1, 1, 1, 1, 2, 2, 2, 2, 2}), toNullableVec({1, 1, 1, 1, 1, 1, 1, 1, 1, 1})}); } diff --git a/dbms/src/Interpreters/ExpressionActions.cpp b/dbms/src/Interpreters/ExpressionActions.cpp index 6985ceef324..09f7894532a 100644 --- a/dbms/src/Interpreters/ExpressionActions.cpp +++ b/dbms/src/Interpreters/ExpressionActions.cpp @@ -213,7 +213,7 @@ void ExpressionAction::prepare(Block & sample_block) /// in case of coprocessor task, the join is always not null, but if the query comes from /// clickhouse client, the join maybe null, skip updating column type if join is null // todo find a new way to update the column type so the type can always be updated. - if (join != nullptr && join->getKind() == ASTTableJoin::Kind::Right) + if (join != nullptr && join->getKind() == ASTTableJoin::Kind::RightOuter) { /// update the column type for left block std::unordered_set keys; diff --git a/dbms/src/Interpreters/ExpressionAnalyzer.cpp b/dbms/src/Interpreters/ExpressionAnalyzer.cpp index 87b5d6d2481..0be9d132b16 100644 --- a/dbms/src/Interpreters/ExpressionAnalyzer.cpp +++ b/dbms/src/Interpreters/ExpressionAnalyzer.cpp @@ -2502,7 +2502,7 @@ void ExpressionAnalyzer::collectJoinedColumns(NameSet & joined_columns, NamesAnd { joined_columns.insert(col.name); - bool make_nullable = table_join.kind == ASTTableJoin::Kind::Left || table_join.kind == ASTTableJoin::Kind::Cross_Left || table_join.kind == ASTTableJoin::Kind::Full; + bool make_nullable = table_join.kind == ASTTableJoin::Kind::LeftOuter || table_join.kind == ASTTableJoin::Kind::Cross_LeftOuter || table_join.kind == ASTTableJoin::Kind::Full; joined_columns_name_type.emplace_back(col.name, make_nullable ? makeNullable(col.type) : col.type); } } diff --git a/dbms/src/Interpreters/InterpreterSelectQuery.cpp b/dbms/src/Interpreters/InterpreterSelectQuery.cpp index 48cf4007d95..377504e2a67 100644 --- a/dbms/src/Interpreters/InterpreterSelectQuery.cpp +++ b/dbms/src/Interpreters/InterpreterSelectQuery.cpp @@ -504,7 +504,7 @@ void InterpreterSelectQuery::executeImpl(Pipeline & pipeline, const BlockInputSt if (expressions.has_join) { const auto & join = static_cast(*query.join()->table_join); - if (join.kind == ASTTableJoin::Kind::Full || join.kind == ASTTableJoin::Kind::Right) + if (join.kind == ASTTableJoin::Kind::Full || join.kind == ASTTableJoin::Kind::RightOuter) pipeline.streams_with_non_joined_data.push_back(expressions.before_join->createStreamWithNonJoinedDataIfFullOrRightJoin( pipeline.firstStream()->getHeader(), 0, diff --git a/dbms/src/Interpreters/Join.cpp b/dbms/src/Interpreters/Join.cpp index ee46233b3fc..11dede06521 100644 --- a/dbms/src/Interpreters/Join.cpp +++ b/dbms/src/Interpreters/Join.cpp @@ -277,11 +277,11 @@ void Join::setSampleBlock(const Block & block) } /// In case of LEFT and FULL joins, if use_nulls, convert joined columns to Nullable. - if (isLeftJoin(kind) || kind == ASTTableJoin::Kind::Full) + if (isLeftOuterJoin(kind) || kind == ASTTableJoin::Kind::Full) for (size_t i = 0; i < num_columns_to_add; ++i) convertColumnToNullable(sample_block_with_columns_to_add.getByPosition(i)); - if (isLeftSemiFamily(kind)) + if (isLeftOuterSemiFamily(kind)) sample_block_with_columns_to_add.insert(ColumnWithTypeAndName(Join::match_helper_type, match_helper_name)); } @@ -529,7 +529,7 @@ void Join::insertFromBlockInternal(Block * stored_block, size_t stream_index) } /// In case of LEFT and FULL joins, if use_nulls, convert joined columns to Nullable. - if (isLeftJoin(kind) || kind == ASTTableJoin::Kind::Full) + if (isLeftOuterJoin(kind) || kind == ASTTableJoin::Kind::Full) { for (size_t i = getFullness(kind) ? keys_size : 0; i < size; ++i) { @@ -602,7 +602,7 @@ void Join::handleOtherConditions(Block & block, std::unique_ptr ColumnUInt8::Container row_filter(filter.size(), 0); - if (isLeftSemiFamily(kind)) + if (isLeftOuterSemiFamily(kind)) { const auto helper_pos = block.getPositionByName(match_helper_name); @@ -641,7 +641,7 @@ void Join::handleOtherConditions(Block & block, std::unique_ptr eq_in_vec = &checkAndGetColumn(orig_filter_column.get())->getData(); } - /// for (anti)leftSemi join, we should keep only one row for each original row of left table. + /// for (anti)leftOuterSemi join, we should keep only one row for each original row of left table. /// and because it is semi join, we needn't save columns of right table, so we just keep the first replica. for (size_t i = 0; i < offsets_to_replicate->size(); ++i) { @@ -723,7 +723,7 @@ void Join::handleOtherConditions(Block & block, std::unique_ptr if (prev_offset < current_offset) { /// for outer join, at least one row must be kept - if (isLeftJoin(kind) && !has_row_kept) + if (isLeftOuterJoin(kind) && !has_row_kept) row_filter[prev_offset] = 1; if (isAntiJoin(kind)) { @@ -740,7 +740,7 @@ void Join::handleOtherConditions(Block & block, std::unique_ptr } prev_offset = current_offset; } - if (isLeftJoin(kind)) + if (isLeftOuterJoin(kind)) { /// for left join, convert right column to null if not joined for (size_t right_table_column : right_table_columns) @@ -870,7 +870,7 @@ Block Join::doJoinBlockHash(ProbeProcessInfo & probe_process_info) const if (rows != process_rows) { - if (isLeftSemiFamily(kind)) + if (isLeftOuterSemiFamily(kind)) { auto helper_col = block.getByName(match_helper_name).column; helper_col = helper_col->cut(probe_process_info.start_row, probe_process_info.end_row); @@ -990,7 +990,7 @@ struct CrossJoinAdder } }; template -struct CrossJoinAdder +struct CrossJoinAdder { static void addFound(MutableColumns & dst_columns, size_t num_existing_columns, ColumnRawPtrs & src_left_columns, size_t num_columns_to_add, size_t start_offset, size_t i, const BlocksList & blocks, IColumn::Filter * is_row_matched, IColumn::Offset & current_offset, IColumn::Offsets * expanded_row_size_after_join, size_t total_right_rows) { @@ -1022,7 +1022,7 @@ struct CrossJoinAdder::addNotFound(dst_columns, num_existing_columns, src_left_columns, num_columns_to_add, start_offset, i, is_row_matched, current_offset, expanded_row_size_after_join); + CrossJoinAdder::addNotFound(dst_columns, num_existing_columns, src_left_columns, num_columns_to_add, start_offset, i, is_row_matched, current_offset, expanded_row_size_after_join); } static bool allRightRowsMaybeAdded() { @@ -1038,7 +1038,7 @@ struct CrossJoinAdder::addNotFound(dst_columns, num_existing_columns, src_left_columns, num_columns_to_add, start_offset, i, is_row_matched, current_offset, expanded_row_size_after_join); + CrossJoinAdder::addNotFound(dst_columns, num_existing_columns, src_left_columns, num_columns_to_add, start_offset, i, is_row_matched, current_offset, expanded_row_size_after_join); } static bool allRightRowsMaybeAdded() { @@ -1046,7 +1046,7 @@ struct CrossJoinAdder -struct CrossJoinAdder +struct CrossJoinAdder { static void addFound(MutableColumns & dst_columns, size_t num_existing_columns, ColumnRawPtrs & src_left_columns, size_t num_columns_to_add, size_t start_offset, size_t i, const BlocksList & blocks, IColumn::Filter * is_row_matched, IColumn::Offset & current_offset, IColumn::Offsets * expanded_row_size_after_join, size_t total_right_rows) { @@ -1055,7 +1055,7 @@ struct CrossJoinAdder } static void addNotFound(MutableColumns & dst_columns, size_t num_existing_columns, ColumnRawPtrs & src_left_columns, size_t num_columns_to_add, size_t start_offset, size_t i, IColumn::Filter * is_row_matched, IColumn::Offset & current_offset, IColumn::Offsets * expanded_row_size_after_join) { - CrossJoinAdder::addNotFound(dst_columns, num_existing_columns, src_left_columns, num_columns_to_add - 1, start_offset, i, is_row_matched, current_offset, expanded_row_size_after_join); + CrossJoinAdder::addNotFound(dst_columns, num_existing_columns, src_left_columns, num_columns_to_add - 1, start_offset, i, is_row_matched, current_offset, expanded_row_size_after_join); dst_columns[num_existing_columns + num_columns_to_add - 1]->insert(FIELD_INT8_0); } static bool allRightRowsMaybeAdded() @@ -1174,28 +1174,28 @@ Block Join::joinBlockCross(ProbeProcessInfo & probe_process_info) const using enum ASTTableJoin::Strictness; using enum ASTTableJoin::Kind; -#define DISPATCH(HAS_NULL_MAP) \ - if (kind == Cross && strictness == All) \ - joinBlockCrossImpl(block, null_map); \ - else if (kind == Cross && strictness == Any) \ - joinBlockCrossImpl(block, null_map); \ - else if (kind == Cross_Left && strictness == All) \ - joinBlockCrossImpl(block, null_map); \ - else if (kind == Cross_Left && strictness == Any) \ - joinBlockCrossImpl(block, null_map); \ - else if (kind == Cross_Anti && strictness == All) \ - joinBlockCrossImpl(block, null_map); \ - else if (kind == Cross_Anti && strictness == Any) \ - joinBlockCrossImpl(block, null_map); \ - else if (kind == Cross_LeftSemi && strictness == All) \ - joinBlockCrossImpl(block, null_map); \ - else if (kind == Cross_LeftSemi && strictness == Any) \ - joinBlockCrossImpl(block, null_map); \ - else if (kind == Cross_LeftAnti && strictness == All) \ - joinBlockCrossImpl(block, null_map); \ - else if (kind == Cross_LeftAnti && strictness == Any) \ - joinBlockCrossImpl(block, null_map); \ - else \ +#define DISPATCH(HAS_NULL_MAP) \ + if (kind == Cross && strictness == All) \ + joinBlockCrossImpl(block, null_map); \ + else if (kind == Cross && strictness == Any) \ + joinBlockCrossImpl(block, null_map); \ + else if (kind == Cross_LeftOuter && strictness == All) \ + joinBlockCrossImpl(block, null_map); \ + else if (kind == Cross_LeftOuter && strictness == Any) \ + joinBlockCrossImpl(block, null_map); \ + else if (kind == Cross_Anti && strictness == All) \ + joinBlockCrossImpl(block, null_map); \ + else if (kind == Cross_Anti && strictness == Any) \ + joinBlockCrossImpl(block, null_map); \ + else if (kind == Cross_LeftOuterSemi && strictness == All) \ + joinBlockCrossImpl(block, null_map); \ + else if (kind == Cross_LeftOuterSemi && strictness == Any) \ + joinBlockCrossImpl(block, null_map); \ + else if (kind == Cross_LeftOuterAnti && strictness == All) \ + joinBlockCrossImpl(block, null_map); \ + else if (kind == Cross_LeftOuterAnti && strictness == Any) \ + joinBlockCrossImpl(block, null_map); \ + else \ throw Exception("Logical error: unknown combination of JOIN", ErrorCodes::LOGICAL_ERROR); if (null_map) @@ -1258,14 +1258,14 @@ Block Join::joinBlockNullAware(ProbeProcessInfo & probe_process_info) const joinBlockNullAwareImpl(block, existing_columns, key_columns, null_map, filter_map, all_key_null_map); else if (kind == NullAware_Anti && strictness == Any) joinBlockNullAwareImpl(block, existing_columns, key_columns, null_map, filter_map, all_key_null_map); - else if (kind == NullAware_LeftSemi && strictness == All) - joinBlockNullAwareImpl(block, existing_columns, key_columns, null_map, filter_map, all_key_null_map); - else if (kind == NullAware_LeftSemi && strictness == Any) - joinBlockNullAwareImpl(block, existing_columns, key_columns, null_map, filter_map, all_key_null_map); - else if (kind == NullAware_LeftAnti && strictness == All) - joinBlockNullAwareImpl(block, existing_columns, key_columns, null_map, filter_map, all_key_null_map); - else if (kind == NullAware_LeftAnti && strictness == Any) - joinBlockNullAwareImpl(block, existing_columns, key_columns, null_map, filter_map, all_key_null_map); + else if (kind == NullAware_LeftOuterSemi && strictness == All) + joinBlockNullAwareImpl(block, existing_columns, key_columns, null_map, filter_map, all_key_null_map); + else if (kind == NullAware_LeftOuterSemi && strictness == Any) + joinBlockNullAwareImpl(block, existing_columns, key_columns, null_map, filter_map, all_key_null_map); + else if (kind == NullAware_LeftOuterAnti && strictness == All) + joinBlockNullAwareImpl(block, existing_columns, key_columns, null_map, filter_map, all_key_null_map); + else if (kind == NullAware_LeftOuterAnti && strictness == Any) + joinBlockNullAwareImpl(block, existing_columns, key_columns, null_map, filter_map, all_key_null_map); else throw Exception("Logical error: unknown combination of JOIN", ErrorCodes::LOGICAL_ERROR); @@ -1335,7 +1335,7 @@ void Join::joinBlockNullAwareImpl( PaddedPODArray * left_semi_column_data = nullptr; PaddedPODArray * left_semi_null_map = nullptr; - if constexpr (KIND == ASTTableJoin::Kind::NullAware_LeftSemi || KIND == ASTTableJoin::Kind::NullAware_LeftAnti) + if constexpr (KIND == ASTTableJoin::Kind::NullAware_LeftOuterSemi || KIND == ASTTableJoin::Kind::NullAware_LeftOuterAnti) { auto * left_semi_column = typeid_cast(added_columns[right_columns - 1].get()); left_semi_column_data = &typeid_cast &>(left_semi_column->getNestedColumn()).getData(); @@ -1580,7 +1580,7 @@ Block Join::joinBlock(ProbeProcessInfo & probe_process_info, bool dry_run) const block = joinBlockHash(probe_process_info); /// for (cartesian)antiLeftSemi join, the meaning of "match-helper" is `non-matched` instead of `matched`. - if (kind == LeftAnti || kind == Cross_LeftAnti) + if (kind == LeftOuterAnti || kind == Cross_LeftOuterAnti) { const auto * nullable_column = checkAndGetColumn(block.getByName(match_helper_name).column.get()); const auto & vec_matched = static_cast *>(nullable_column->getNestedColumnPtr().get())->getData(); diff --git a/dbms/src/Interpreters/Join.h b/dbms/src/Interpreters/Join.h index 10fba9fccac..b0ab4a536ea 100644 --- a/dbms/src/Interpreters/Join.h +++ b/dbms/src/Interpreters/Join.h @@ -255,7 +255,7 @@ class Join static const String flag_mapped_entry_helper_prefix; static const DataTypePtr flag_mapped_entry_helper_type; - // only use for left semi joins. + // only use for left outer semi joins. const String match_helper_name; // only use for right semi, right anti joins with other conditions, // used to name the column that records matched map entry before other conditions filter diff --git a/dbms/src/Interpreters/JoinPartition.cpp b/dbms/src/Interpreters/JoinPartition.cpp index 0eb62f770c8..e7b4f3d3300 100644 --- a/dbms/src/Interpreters/JoinPartition.cpp +++ b/dbms/src/Interpreters/JoinPartition.cpp @@ -742,7 +742,7 @@ template -struct Adder +struct Adder { static bool addFound(const typename Map::ConstLookupResult & it, size_t num_columns_to_add, MutableColumns & added_columns, size_t /*i*/, IColumn::Filter * /*filter*/, IColumn::Offset & /*current_offset*/, IColumn::Offsets * /*offsets*/, const std::vector & right_indexes, ProbeProcessInfo & /*probe_process_info*/, MutableColumnPtr & /* ptr_col */) { @@ -798,7 +798,7 @@ struct Adder }; template -struct Adder +struct Adder { static bool addFound(const typename Map::ConstLookupResult & /*it*/, size_t num_columns_to_add, MutableColumns & added_columns, size_t /*i*/, IColumn::Filter * /*filter*/, IColumn::Offset & /*current_offset*/, IColumn::Offsets * /*offsets*/, const std::vector & /*right_indexes*/, ProbeProcessInfo & /*probe_process_info*/, MutableColumnPtr & /* ptr_col */) { @@ -818,7 +818,7 @@ struct Adder }; template -struct Adder +struct Adder { static bool addFound(const typename Map::ConstLookupResult & it, size_t num_columns_to_add, MutableColumns & added_columns, size_t i, IColumn::Filter * /*filter*/, IColumn::Offset & current_offset, IColumn::Offsets * offsets, const std::vector & right_indexes, ProbeProcessInfo & /*probe_process_info*/, MutableColumnPtr & /* ptr_col */) { @@ -1228,8 +1228,8 @@ std::pair>, std::list>, std::list> res; res.reserve(rows); std::list *> res_list; - /// We can just consider the result of left semi join because `NASemiJoinResult::setResult` will correct - /// the result if it's not left semi join. + /// We can just consider the result of left outer semi join because `NASemiJoinResult::setResult` will correct + /// the result if it's not left outer semi join. for (size_t i = 0; i < rows; ++i) { if constexpr (has_filter_map) @@ -1447,34 +1447,34 @@ void JoinPartition::probeBlock( probe_process_info, \ record_mapped_entry_column); - if (kind == Left && strictness == Any) - CALL(Left, Any, MapsAny) + if (kind == LeftOuter && strictness == Any) + CALL(LeftOuter, Any, MapsAny) else if (kind == Inner && strictness == Any) CALL(Inner, Any, MapsAny) - else if (kind == Left && strictness == All) - CALL(Left, All, MapsAll) + else if (kind == LeftOuter && strictness == All) + CALL(LeftOuter, All, MapsAll) else if (kind == Inner && strictness == All) CALL(Inner, All, MapsAll) else if (kind == Full && strictness == Any) - CALL(Left, Any, MapsAnyFull) - else if (kind == Right && strictness == Any) + CALL(LeftOuter, Any, MapsAnyFull) + else if (kind == RightOuter && strictness == Any) CALL(Inner, Any, MapsAnyFull) else if (kind == Full && strictness == All) - CALL(Left, All, MapsAllFull) - else if (kind == Right && strictness == All) + CALL(LeftOuter, All, MapsAllFull) + else if (kind == RightOuter && strictness == All) CALL(Inner, All, MapsAllFull) else if (kind == Anti && strictness == Any) CALL(Anti, Any, MapsAny) else if (kind == Anti && strictness == All) CALL(Anti, All, MapsAll) - else if (kind == LeftSemi && strictness == Any) - CALL(LeftSemi, Any, MapsAny) - else if (kind == LeftSemi && strictness == All) - CALL(LeftSemi, All, MapsAll) - else if (kind == LeftAnti && strictness == Any) - CALL(LeftSemi, Any, MapsAny) - else if (kind == LeftAnti && strictness == All) - CALL(LeftSemi, All, MapsAll) + else if (kind == LeftOuterSemi && strictness == Any) + CALL(LeftOuterSemi, Any, MapsAny) + else if (kind == LeftOuterSemi && strictness == All) + CALL(LeftOuterSemi, All, MapsAll) + else if (kind == LeftOuterAnti && strictness == Any) + CALL(LeftOuterSemi, Any, MapsAny) + else if (kind == LeftOuterAnti && strictness == All) + CALL(LeftOuterSemi, All, MapsAll) else if (kind == RightSemi && record_mapped_entry_column) CALL(RightSemi, All, MapsAllFullWithRowFlag) else if (kind == RightSemi && !record_mapped_entry_column) diff --git a/dbms/src/Interpreters/JoinUtils.cpp b/dbms/src/Interpreters/JoinUtils.cpp index 287c28d9d6f..9aff6ea5d3b 100644 --- a/dbms/src/Interpreters/JoinUtils.cpp +++ b/dbms/src/Interpreters/JoinUtils.cpp @@ -145,7 +145,7 @@ void ProbeProcessInfo::prepareForProbe(const Names & key_names, const String & f convertColumnToNullable(block.getByPosition(i)); } } - if (((kind == ASTTableJoin::Kind::Inner || kind == ASTTableJoin::Kind::Right) && strictness == ASTTableJoin::Strictness::Any) + if (((kind == ASTTableJoin::Kind::Inner || kind == ASTTableJoin::Kind::RightOuter) && strictness == ASTTableJoin::Strictness::Any) || kind == ASTTableJoin::Kind::Anti) filter = std::make_unique(block.rows()); if (strictness == ASTTableJoin::Strictness::All) @@ -187,10 +187,10 @@ void computeDispatchHash(size_t rows, bool mayProbeSideExpandedAfterJoin(ASTTableJoin::Kind kind, ASTTableJoin::Strictness strictness) { - /// null aware semi/left semi/anti join never expand the probe side + /// null aware semi/left outer semi/anti join never expand the probe side if (isNullAwareSemiFamily(kind)) return false; - if (isLeftSemiFamily(kind)) + if (isLeftOuterSemiFamily(kind)) return false; if (isAntiJoin(kind)) return false; diff --git a/dbms/src/Interpreters/JoinUtils.h b/dbms/src/Interpreters/JoinUtils.h index 1ac51ccfcf7..69cfc065f6b 100644 --- a/dbms/src/Interpreters/JoinUtils.h +++ b/dbms/src/Interpreters/JoinUtils.h @@ -25,20 +25,20 @@ namespace DB /// Do I need to use the hash table maps_*_full, in which we remember whether the row was joined and fill left columns if not joined inline bool getFullness(ASTTableJoin::Kind kind) { - return kind == ASTTableJoin::Kind::Right || kind == ASTTableJoin::Kind::Cross_Right || kind == ASTTableJoin::Kind::Full; + return kind == ASTTableJoin::Kind::RightOuter || kind == ASTTableJoin::Kind::Cross_RightOuter || kind == ASTTableJoin::Kind::Full; } -/// For semi and anti join A semi/anti join B, that uses A as build table +/// For semi and anti join: A semi/anti join B, that uses A as build table inline bool isRightSemiFamily(ASTTableJoin::Kind kind) { return kind == ASTTableJoin::Kind::RightSemi || kind == ASTTableJoin::Kind::RightAnti; } -inline bool isLeftJoin(ASTTableJoin::Kind kind) +inline bool isLeftOuterJoin(ASTTableJoin::Kind kind) { - return kind == ASTTableJoin::Kind::Left || kind == ASTTableJoin::Kind::Cross_Left; + return kind == ASTTableJoin::Kind::LeftOuter || kind == ASTTableJoin::Kind::Cross_LeftOuter; } -inline bool isRightJoin(ASTTableJoin::Kind kind) +inline bool isRightOuterJoin(ASTTableJoin::Kind kind) { - return kind == ASTTableJoin::Kind::Right || kind == ASTTableJoin::Kind::Cross_Right; + return kind == ASTTableJoin::Kind::RightOuter || kind == ASTTableJoin::Kind::Cross_RightOuter; } inline bool isInnerJoin(ASTTableJoin::Kind kind) { @@ -50,21 +50,21 @@ inline bool isAntiJoin(ASTTableJoin::Kind kind) } inline bool isCrossJoin(ASTTableJoin::Kind kind) { - return kind == ASTTableJoin::Kind::Cross || kind == ASTTableJoin::Kind::Cross_Left - || kind == ASTTableJoin::Kind::Cross_Right || kind == ASTTableJoin::Kind::Cross_Anti - || kind == ASTTableJoin::Kind::Cross_LeftSemi || kind == ASTTableJoin::Kind::Cross_LeftAnti; + return kind == ASTTableJoin::Kind::Cross || kind == ASTTableJoin::Kind::Cross_LeftOuter + || kind == ASTTableJoin::Kind::Cross_RightOuter || kind == ASTTableJoin::Kind::Cross_Anti + || kind == ASTTableJoin::Kind::Cross_LeftOuterSemi || kind == ASTTableJoin::Kind::Cross_LeftOuterAnti; } -/// (cartesian/null-aware) (anti) left semi join. -inline bool isLeftSemiFamily(ASTTableJoin::Kind kind) +/// (cartesian/null-aware) (anti) left outer semi join. +inline bool isLeftOuterSemiFamily(ASTTableJoin::Kind kind) { - return kind == ASTTableJoin::Kind::LeftSemi || kind == ASTTableJoin::Kind::LeftAnti - || kind == ASTTableJoin::Kind::Cross_LeftSemi || kind == ASTTableJoin::Kind::Cross_LeftAnti - || kind == ASTTableJoin::Kind::NullAware_LeftSemi || kind == ASTTableJoin::Kind::NullAware_LeftAnti; + return kind == ASTTableJoin::Kind::LeftOuterSemi || kind == ASTTableJoin::Kind::LeftOuterAnti + || kind == ASTTableJoin::Kind::Cross_LeftOuterSemi || kind == ASTTableJoin::Kind::Cross_LeftOuterAnti + || kind == ASTTableJoin::Kind::NullAware_LeftOuterSemi || kind == ASTTableJoin::Kind::NullAware_LeftOuterAnti; } inline bool isNullAwareSemiFamily(ASTTableJoin::Kind kind) { - return kind == ASTTableJoin::Kind::NullAware_Anti || kind == ASTTableJoin::Kind::NullAware_LeftAnti - || kind == ASTTableJoin::Kind::NullAware_LeftSemi; + return kind == ASTTableJoin::Kind::NullAware_Anti || kind == ASTTableJoin::Kind::NullAware_LeftOuterAnti + || kind == ASTTableJoin::Kind::NullAware_LeftOuterSemi; } inline bool needRecordNotInsertRows(ASTTableJoin::Kind kind) { diff --git a/dbms/src/Interpreters/NullAwareSemiJoinHelper.cpp b/dbms/src/Interpreters/NullAwareSemiJoinHelper.cpp index 04a6539d3c2..8637611a856 100644 --- a/dbms/src/Interpreters/NullAwareSemiJoinHelper.cpp +++ b/dbms/src/Interpreters/NullAwareSemiJoinHelper.cpp @@ -34,8 +34,8 @@ NASemiJoinResult::NASemiJoinResult(size_t row_num_, NASemiJoin , pos_in_columns(0) , map_it(map_it_) { - static_assert(KIND == NullAware_Anti || KIND == NullAware_LeftAnti - || KIND == NullAware_LeftSemi); + static_assert(KIND == NullAware_Anti || KIND == NullAware_LeftOuterAnti + || KIND == NullAware_LeftOuterSemi); } template @@ -215,13 +215,13 @@ NASemiJoinHelper::NASemiJoinHelper( , max_block_size(max_block_size_) , non_equal_conditions(non_equal_conditions_) { - static_assert(KIND == NullAware_Anti || KIND == NullAware_LeftAnti - || KIND == NullAware_LeftSemi); + static_assert(KIND == NullAware_Anti || KIND == NullAware_LeftOuterAnti + || KIND == NullAware_LeftOuterSemi); static_assert(STRICTNESS == Any || STRICTNESS == All); RUNTIME_CHECK(block.columns() == left_columns + right_columns); - if constexpr (KIND == NullAware_LeftAnti || KIND == NullAware_LeftSemi) + if constexpr (KIND == NullAware_LeftOuterAnti || KIND == NullAware_LeftOuterSemi) { /// The last column is `match_helper`. right_columns -= 1; diff --git a/dbms/src/Interpreters/NullAwareSemiJoinHelper.h b/dbms/src/Interpreters/NullAwareSemiJoinHelper.h index 5487243c1bd..3220ab636c9 100644 --- a/dbms/src/Interpreters/NullAwareSemiJoinHelper.h +++ b/dbms/src/Interpreters/NullAwareSemiJoinHelper.h @@ -80,13 +80,13 @@ class NASemiJoinResult public: NASemiJoinResult(size_t row_num, NASemiJoinStep step, const void * map_it); - /// For convenience, callers can only consider the result of left semi join. - /// This function will correct the result if it's not left semi join. + /// For convenience, callers can only consider the result of left outer semi join. + /// This function will correct the result if it's not left outer semi join. template void setResult() { step = NASemiJoinStep::DONE; - if constexpr (KIND == ASTTableJoin::Kind::NullAware_LeftSemi) + if constexpr (KIND == ASTTableJoin::Kind::NullAware_LeftOuterSemi) { result = RES; return; @@ -185,12 +185,12 @@ class NASemiJoinHelper const JoinNonEqualConditions & non_equal_conditions; }; -#define APPLY_FOR_NULL_AWARE_JOIN(M) \ - M(DB::ASTTableJoin::Kind::NullAware_LeftSemi, DB::ASTTableJoin::Strictness::Any, DB::MapsAny) \ - M(DB::ASTTableJoin::Kind::NullAware_LeftSemi, DB::ASTTableJoin::Strictness::All, DB::MapsAll) \ - M(DB::ASTTableJoin::Kind::NullAware_LeftAnti, DB::ASTTableJoin::Strictness::Any, DB::MapsAny) \ - M(DB::ASTTableJoin::Kind::NullAware_LeftAnti, DB::ASTTableJoin::Strictness::All, DB::MapsAll) \ - M(DB::ASTTableJoin::Kind::NullAware_Anti, DB::ASTTableJoin::Strictness::Any, DB::MapsAny) \ +#define APPLY_FOR_NULL_AWARE_JOIN(M) \ + M(DB::ASTTableJoin::Kind::NullAware_LeftOuterSemi, DB::ASTTableJoin::Strictness::Any, DB::MapsAny) \ + M(DB::ASTTableJoin::Kind::NullAware_LeftOuterSemi, DB::ASTTableJoin::Strictness::All, DB::MapsAll) \ + M(DB::ASTTableJoin::Kind::NullAware_LeftOuterAnti, DB::ASTTableJoin::Strictness::Any, DB::MapsAny) \ + M(DB::ASTTableJoin::Kind::NullAware_LeftOuterAnti, DB::ASTTableJoin::Strictness::All, DB::MapsAll) \ + M(DB::ASTTableJoin::Kind::NullAware_Anti, DB::ASTTableJoin::Strictness::Any, DB::MapsAny) \ M(DB::ASTTableJoin::Kind::NullAware_Anti, DB::ASTTableJoin::Strictness::All, DB::MapsAll) } // namespace DB diff --git a/dbms/src/Parsers/ASTTablesInSelectQuery.cpp b/dbms/src/Parsers/ASTTablesInSelectQuery.cpp index d84bc3dd583..5a97eec60bc 100644 --- a/dbms/src/Parsers/ASTTablesInSelectQuery.cpp +++ b/dbms/src/Parsers/ASTTablesInSelectQuery.cpp @@ -155,10 +155,10 @@ void ASTTableJoin::formatImplBeforeTable(const FormatSettings & settings, Format case Kind::Inner: settings.ostr << "INNER JOIN"; break; - case Kind::Left: + case Kind::LeftOuter: settings.ostr << "LEFT JOIN"; break; - case Kind::Right: + case Kind::RightOuter: settings.ostr << "RIGHT JOIN"; break; case Kind::Full: diff --git a/dbms/src/Parsers/ASTTablesInSelectQuery.h b/dbms/src/Parsers/ASTTablesInSelectQuery.h index 3037b0f2ef6..b00d9d5ee90 100644 --- a/dbms/src/Parsers/ASTTablesInSelectQuery.h +++ b/dbms/src/Parsers/ASTTablesInSelectQuery.h @@ -92,26 +92,26 @@ struct ASTTableJoin : public IAST enum class Kind { Inner, /// Leave ony rows that was JOINed. - Left, /// If in "right" table there is no corresponding rows, use default values instead. - Right, + LeftOuter, /// If in "right" table there is no corresponding rows, use default values instead. + RightOuter, Full, Cross, /// Direct product. Strictness and condition doesn't matter. Comma, /// Same as direct product. Intended to be converted to INNER JOIN with conditions from WHERE. Anti, /// anti join, return un-joined rows of the left table - LeftSemi, /// left semi join, used by TiFlash, it means if row a in table A matches some rows in B, output (a, true), otherwise, output (a, false). - LeftAnti, /// anti left semi join, used by TiFlash, it means if row a in table A matches some rows in B, output (a, false), otherwise, output (a, true). - Cross_Left, /// cartesian left out join, used by TiFlash - Cross_Right, /// cartesian right out join, used by TiFlash, in the implementation, it will be converted to cartesian left out join + LeftOuterSemi, /// left outer semi join, used by TiFlash, it means if row a in table A matches some rows in B, output (a, true), otherwise, output (a, false). + LeftOuterAnti, /// anti left outer semi join, used by TiFlash, it means if row a in table A matches some rows in B, output (a, false), otherwise, output (a, true). + Cross_LeftOuter, /// cartesian left out join, used by TiFlash + Cross_RightOuter, /// cartesian right out join, used by TiFlash, in the implementation, it will be converted to cartesian left out join Cross_Anti, /// cartesian anti join, used by TiFlash - Cross_LeftSemi, /// cartesian version of left semi join, used by TiFlash. - Cross_LeftAnti, /// cartesian version of left anti semi join, used by TiFlash. + Cross_LeftOuterSemi, /// cartesian version of left outer semi join, used by TiFlash. + Cross_LeftOuterAnti, /// cartesian version of left outer anti semi join, used by TiFlash. /// Note that there is no NullAware_Semi because semi join does not need to be null-aware. /// In semi join, if it's found in hash table, result is 1, otherwise, 0 or NULL(they're the same). /// However, in anti semi join, if it's found in hash table, result is 0, otherwise, 1 or NULL(they're different). NullAware_Anti, /// null-aware version of anti semi join, used by TiFlash. /// For left (anti) semi join, the exact result must be given, so both of them need to be null-aware. - NullAware_LeftSemi, /// null-aware version of left semi join, used by TiFlash. - NullAware_LeftAnti, /// null-aware version of left anti semi join, used by TiFlash. + NullAware_LeftOuterSemi, /// null-aware version of left outer semi join, used by TiFlash. + NullAware_LeftOuterAnti, /// null-aware version of left outer anti semi join, used by TiFlash. RightSemi, /// semi join, A semi join B, while using table A to build hash table. RightAnti, /// anti semi join, A anti semi join B, while using table A to build hash table. }; diff --git a/dbms/src/Parsers/ParserTablesInSelectQuery.cpp b/dbms/src/Parsers/ParserTablesInSelectQuery.cpp index 5a2cbe99298..970a02bc2d3 100644 --- a/dbms/src/Parsers/ParserTablesInSelectQuery.cpp +++ b/dbms/src/Parsers/ParserTablesInSelectQuery.cpp @@ -110,9 +110,9 @@ bool ParserTablesInSelectQueryElement::parseImpl(Pos & pos, ASTPtr & node, Expec if (ParserKeyword("INNER").ignore(pos)) table_join->kind = ASTTableJoin::Kind::Inner; else if (ParserKeyword("LEFT").ignore(pos)) - table_join->kind = ASTTableJoin::Kind::Left; + table_join->kind = ASTTableJoin::Kind::LeftOuter; else if (ParserKeyword("RIGHT").ignore(pos)) - table_join->kind = ASTTableJoin::Kind::Right; + table_join->kind = ASTTableJoin::Kind::RightOuter; else if (ParserKeyword("FULL").ignore(pos)) table_join->kind = ASTTableJoin::Kind::Full; else if (ParserKeyword("CROSS").ignore(pos)) @@ -128,8 +128,8 @@ bool ParserTablesInSelectQueryElement::parseImpl(Pos & pos, ASTPtr & node, Expec throw Exception("You must not specify ANY or ALL for CROSS JOIN.", ErrorCodes::SYNTAX_ERROR); /// Optional OUTER keyword for outer joins. - if (table_join->kind == ASTTableJoin::Kind::Left - || table_join->kind == ASTTableJoin::Kind::Right + if (table_join->kind == ASTTableJoin::Kind::LeftOuter + || table_join->kind == ASTTableJoin::Kind::RightOuter || table_join->kind == ASTTableJoin::Kind::Full) { ParserKeyword("OUTER").ignore(pos);