From 08199000c6ded38064225ea89ca293dc3c2ef18d Mon Sep 17 00:00:00 2001 From: xufei Date: Wed, 12 Apr 2023 17:56:53 +0800 Subject: [PATCH] more refine Signed-off-by: xufei --- dbms/src/Interpreters/Join.cpp | 7 ++++--- dbms/src/Interpreters/Join.h | 3 ++- dbms/src/Interpreters/JoinUtils.cpp | 16 ++++++++++++++++ dbms/src/Interpreters/JoinUtils.h | 3 +++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/dbms/src/Interpreters/Join.cpp b/dbms/src/Interpreters/Join.cpp index b27c9d7e272..e440977a577 100644 --- a/dbms/src/Interpreters/Join.cpp +++ b/dbms/src/Interpreters/Join.cpp @@ -130,6 +130,8 @@ Join::Join( , match_helper_name(match_helper_name) , kind(kind_) , strictness(strictness_) + , original_strictness(strictness) + , may_block_expanded_after_join_block(mayBlockExpandedAfterJoinBlock(kind, strictness)) , key_names_left(key_names_left_) , key_names_right(key_names_right_) , build_concurrency(0) @@ -138,7 +140,6 @@ Join::Join( , active_probe_threads(0) , collators(collators_) , non_equal_conditions(non_equal_conditions_) - , original_strictness(strictness) , max_block_size(max_block_size_) , max_bytes_before_external_join(max_bytes_before_external_join_) , build_spill_config(build_spill_config_) @@ -980,8 +981,8 @@ Block Join::joinBlockHash(ProbeProcessInfo & probe_process_info) const result_blocks.push_back(std::move(block)); /// exit the while loop if /// 1. probe_process_info.all_rows_joined_finish is true, which means all the rows in current block is processed - /// 2. result_rows exceeds the min_result_block_size - if (probe_process_info.all_rows_joined_finish || result_rows >= probe_process_info.min_result_block_size) + /// 2. the block may be expanded after join and result_rows exceeds the min_result_block_size + if (probe_process_info.all_rows_joined_finish || (may_block_expanded_after_join_block && result_rows >= probe_process_info.min_result_block_size)) break; } assert(!result_blocks.empty()); diff --git a/dbms/src/Interpreters/Join.h b/dbms/src/Interpreters/Join.h index 60b7c3dc730..b4e823ef808 100644 --- a/dbms/src/Interpreters/Join.h +++ b/dbms/src/Interpreters/Join.h @@ -265,6 +265,8 @@ class Join ASTTableJoin::Kind kind; ASTTableJoin::Strictness strictness; + ASTTableJoin::Strictness original_strictness; + const bool may_block_expanded_after_join_block; /// Names of key columns (columns for equi-JOIN) in "left" table (in the order they appear in USING clause). const Names key_names_left; @@ -290,7 +292,6 @@ class Join const JoinNonEqualConditions non_equal_conditions; - ASTTableJoin::Strictness original_strictness; size_t max_block_size; /** Blocks of "right" table. */ diff --git a/dbms/src/Interpreters/JoinUtils.cpp b/dbms/src/Interpreters/JoinUtils.cpp index 8cbe6f72b1b..e62673575bf 100644 --- a/dbms/src/Interpreters/JoinUtils.cpp +++ b/dbms/src/Interpreters/JoinUtils.cpp @@ -66,4 +66,20 @@ void computeDispatchHash(size_t rows, data[i] = updateHashValue(join_restore_round, data[i]); } } + +bool mayBlockExpandedAfterJoinBlock(ASTTableJoin::Kind kind, ASTTableJoin::Strictness strictness) +{ + /// null aware semi/left semi/anti join never expand the block + if (isNullAwareSemiFamily(kind)) + return false; + if (isLeftSemiFamily(kind)) + return false; + if (isAntiJoin(kind)) + return false; + /// strictness == Any means semi join, it never expand the block + if (strictness == ASTTableJoin::Strictness::Any) + return false; + /// for all the other cases, return true by default + return true; +} } // namespace DB diff --git a/dbms/src/Interpreters/JoinUtils.h b/dbms/src/Interpreters/JoinUtils.h index fe4f721d4da..4b55cfdf7e0 100644 --- a/dbms/src/Interpreters/JoinUtils.h +++ b/dbms/src/Interpreters/JoinUtils.h @@ -58,6 +58,9 @@ inline bool isNullAwareSemiFamily(ASTTableJoin::Kind kind) return kind == ASTTableJoin::Kind::NullAware_Anti || kind == ASTTableJoin::Kind::NullAware_LeftAnti || kind == ASTTableJoin::Kind::NullAware_LeftSemi; } + +bool mayBlockExpandedAfterJoinBlock(ASTTableJoin::Kind kind, ASTTableJoin::Strictness strictness); + struct ProbeProcessInfo { Block block;