diff --git a/src/Interpreters/HashJoin.cpp b/src/Interpreters/HashJoin.cpp index 9fd577318f8..dc041094381 100644 --- a/src/Interpreters/HashJoin.cpp +++ b/src/Interpreters/HashJoin.cpp @@ -178,7 +178,7 @@ namespace JoinStuff } } -static ColumnWithTypeAndName correctNullability(ColumnWithTypeAndName && column, bool nullable) +static void correctNullabilityInplace(ColumnWithTypeAndName & column, bool nullable) { if (nullable) { @@ -193,11 +193,9 @@ static ColumnWithTypeAndName correctNullability(ColumnWithTypeAndName && column, JoinCommon::removeColumnNullability(column); } - - return std::move(column); } -static ColumnWithTypeAndName correctNullability(ColumnWithTypeAndName && column, bool nullable, const ColumnUInt8 & negative_null_map) +static void correctNullabilityInplace(ColumnWithTypeAndName & column, bool nullable, const ColumnUInt8 & negative_null_map) { if (nullable) { @@ -211,8 +209,6 @@ static ColumnWithTypeAndName correctNullability(ColumnWithTypeAndName && column, } else JoinCommon::removeColumnNullability(column); - - return std::move(column); } HashJoin::HashJoin(std::shared_ptr table_join_, const Block & right_sample_block_, bool any_take_last_row_) @@ -1475,7 +1471,7 @@ void HashJoin::joinBlockImpl( ColumnWithTypeAndName right_col(col.column, col.type, right_col_name); if (right_col.type->lowCardinality() != right_key.type->lowCardinality()) JoinCommon::changeLowCardinalityInplace(right_col); - right_col = correctNullability(std::move(right_col), is_nullable); + correctNullabilityInplace(right_col, is_nullable); block.insert(std::move(right_col)); } } @@ -1509,7 +1505,7 @@ void HashJoin::joinBlockImpl( ColumnWithTypeAndName right_col(thin_column, col.type, right_col_name); if (right_col.type->lowCardinality() != right_key.type->lowCardinality()) JoinCommon::changeLowCardinalityInplace(right_col); - right_col = correctNullability(std::move(right_col), is_nullable, null_map_filter); + correctNullabilityInplace(right_col, is_nullable, null_map_filter); block.insert(std::move(right_col)); if constexpr (jf.need_replication) @@ -2020,7 +2016,8 @@ BlocksList HashJoin::releaseJoinedBlocks() for (size_t i = 0; i < positions.size(); ++i) { auto & column = saved_block.getByPosition(positions[i]); - restored_block.insert(correctNullability(std::move(column), is_nullable[i])); + correctNullabilityInplace(column, is_nullable[i]); + restored_block.insert(column); } restored_blocks.emplace_back(std::move(restored_block)); } @@ -2028,7 +2025,6 @@ BlocksList HashJoin::releaseJoinedBlocks() return restored_blocks; } - const ColumnWithTypeAndName & HashJoin::rightAsofKeyColumn() const { /// It should be nullable when right side is nullable diff --git a/tests/queries/0_stateless/02503_join_switch_alias_fuzz.reference b/tests/queries/0_stateless/02503_join_switch_alias_fuzz.reference new file mode 100644 index 00000000000..af591cd7818 --- /dev/null +++ b/tests/queries/0_stateless/02503_join_switch_alias_fuzz.reference @@ -0,0 +1 @@ +1 \N 1 \N diff --git a/tests/queries/0_stateless/02503_join_switch_alias_fuzz.sql b/tests/queries/0_stateless/02503_join_switch_alias_fuzz.sql new file mode 100644 index 00000000000..28d64bf3881 --- /dev/null +++ b/tests/queries/0_stateless/02503_join_switch_alias_fuzz.sql @@ -0,0 +1,4 @@ +SELECT * FROM (SELECT 1 AS id, '' AS test) AS a +LEFT JOIN (SELECT test, 1 AS id, NULL AS test) AS b ON b.id = a.id +SETTINGS join_algorithm = 'auto', max_rows_in_join = 1, allow_experimental_analyzer = 1 +;