diff --git a/src/Interpreters/HashJoin/HashJoinMethods.h b/src/Interpreters/HashJoin/HashJoinMethods.h index af07da53019..5be3b86c1fb 100644 --- a/src/Interpreters/HashJoin/HashJoinMethods.h +++ b/src/Interpreters/HashJoin/HashJoinMethods.h @@ -11,6 +11,7 @@ #include #include +#include "Parsers/ExpressionListParsers.h" namespace DB { @@ -149,9 +150,10 @@ private: template static void setUsed(IColumn::Filter & filter [[maybe_unused]], size_t pos [[maybe_unused]]); - template + template static ColumnPtr buildAdditionalFilter( size_t left_start_row, + const Selector & selector, const std::vector & selected_rows, const std::vector & row_replicate_offset, AddedColumns & added_columns); diff --git a/src/Interpreters/HashJoin/HashJoinMethodsImpl.h b/src/Interpreters/HashJoin/HashJoinMethodsImpl.h index 2b5e92b6841..f415ed6f44f 100644 --- a/src/Interpreters/HashJoin/HashJoinMethodsImpl.h +++ b/src/Interpreters/HashJoin/HashJoinMethodsImpl.h @@ -358,6 +358,12 @@ size_t HashJoinMethods::joinRightColumnsSwitchMu if (added_columns.additional_filter_expression) { const bool mark_per_row_used = join_features.right || join_features.full || mapv.size() > 1; + LOG_DEBUG( + &Poco::Logger::get("debug"), + "__PRETTY_FUNCTION__={}, __LINE__={}, mark_per_row_used={}", + __PRETTY_FUNCTION__, + __LINE__, + mark_per_row_used); return joinRightColumnsWithAddtitionalFilter( std::forward>(key_getter_vector), mapv, @@ -554,9 +560,10 @@ void HashJoinMethods::setUsed(IColumn::Filter & } template -template +template ColumnPtr HashJoinMethods::buildAdditionalFilter( size_t left_start_row, + const Selector & selector, const std::vector & selected_rows, const std::vector & row_replicate_offset, AddedColumns & added_columns) @@ -569,12 +576,14 @@ ColumnPtr HashJoinMethods::buildAdditionalFilter result_column = ColumnUInt8::create(); break; } + LOG_DEBUG(&Poco::Logger::get("debug"), "__PRETTY_FUNCTION__={}, __LINE__={}", __PRETTY_FUNCTION__, __LINE__); const Block & sample_right_block = *((*selected_rows.begin())->block); if (!sample_right_block || !added_columns.additional_filter_expression) { auto filter = ColumnUInt8::create(); filter->insertMany(1, selected_rows.size()); result_column = std::move(filter); + LOG_DEBUG(&Poco::Logger::get("debug"), "__PRETTY_FUNCTION__={}, __LINE__={}", __PRETTY_FUNCTION__, __LINE__); break; } @@ -584,6 +593,7 @@ ColumnPtr HashJoinMethods::buildAdditionalFilter Block block; added_columns.additional_filter_expression->execute(block); result_column = block.getByPosition(0).column->cloneResized(selected_rows.size()); + LOG_DEBUG(&Poco::Logger::get("debug"), "__PRETTY_FUNCTION__={}, __LINE__={}", __PRETTY_FUNCTION__, __LINE__); break; } NameSet required_column_names; @@ -600,6 +610,14 @@ ColumnPtr HashJoinMethods::buildAdditionalFilter for (const auto & selected_row : selected_rows) { const auto & src_col = selected_row->block->getByPosition(right_col_pos); + if (executed_block.columns() == 0) + LOG_DEBUG( + &Poco::Logger::get("debug"), + "__PRETTY_FUNCTION__={}, __LINE__={}, src_col.name={}, selected_row->row_num={}", + __PRETTY_FUNCTION__, + __LINE__, + src_col.name, + selected_row->row_num); new_col->insertFrom(*src_col.column, selected_row->row_num); } executed_block.insert({std::move(new_col), col.type, col.name}); @@ -619,7 +637,9 @@ ColumnPtr HashJoinMethods::buildAdditionalFilter const size_t & left_offset = row_replicate_offset[i]; size_t rows = left_offset - prev_left_offset; if (rows) - new_col->insertManyFrom(*src_col->column, left_start_row + i - 1, rows); + { + new_col->insertManyFrom(*src_col->column, selector[left_start_row + i - 1], rows); + } prev_left_offset = left_offset; } executed_block.insert({std::move(new_col), src_col->type, col_name}); @@ -902,7 +922,7 @@ size_t HashJoinMethods::joinRightColumnsWithAddt it, left_start_row); } - auto filter_col = buildAdditionalFilter(left_start_row, selected_rows, row_replicate_offset, added_columns); + auto filter_col = buildAdditionalFilter(left_start_row, selector, selected_rows, row_replicate_offset, added_columns); copy_final_matched_rows(left_start_row, filter_col); if constexpr (join_features.need_replication)