Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion be/src/pipeline/exec/hashjoin_build_sink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,22 @@ void HashJoinBuildSinkLocalState::_hash_table_init(RuntimeState* state) {
}
return;
}

std::vector<vectorized::DataTypePtr> data_types;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comment for the change

for (size_t i = 0; i != _build_expr_ctxs.size(); ++i) {
auto& ctx = _build_expr_ctxs[i];
auto data_type = ctx->root()->data_type();

/// For 'null safe equal' join,
/// the build key column maybe be converted to nullable from non-nullable.
if (p._should_convert_to_nullable[i]) {
data_type = vectorized::make_nullable(data_type);
}
data_types.emplace_back(std::move(data_type));
}

if (!try_get_hash_map_context_fixed<JoinHashMap, HashCRC32>(
*_shared_state->hash_table_variants, _build_expr_ctxs)) {
*_shared_state->hash_table_variants, data_types)) {
_shared_state->hash_table_variants
->emplace<vectorized::SerializedHashTableContext>();
}
Expand Down
15 changes: 12 additions & 3 deletions be/src/vec/common/hash_table/hash_map_context_creator.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,23 @@ void get_hash_map_context_fixed(Variant& variant, size_t size, bool has_nullable
template <template <typename... Args> typename HashMap, template <typename> typename Hash,
typename... Mapped, typename Variant>
bool try_get_hash_map_context_fixed(Variant& variant, const VExprContextSPtrs& expr_ctxs) {
std::vector<DataTypePtr> data_types;
for (const auto& ctx : expr_ctxs) {
data_types.emplace_back(ctx->root()->data_type());
}
return try_get_hash_map_context_fixed<HashMap, Hash, Mapped...>(variant, data_types);
}

template <template <typename... Args> typename HashMap, template <typename> typename Hash,
typename... Mapped, typename Variant>
bool try_get_hash_map_context_fixed(Variant& variant, const std::vector<DataTypePtr>& data_types) {
Sizes key_sizes;

bool use_fixed_key = true;
bool has_null = false;
size_t key_byte_size = 0;

for (auto ctx : expr_ctxs) {
const auto& data_type = ctx->root()->data_type();
for (const auto& data_type : data_types) {
if (!data_type->have_maximum_size_of_value()) {
use_fixed_key = false;
break;
Expand All @@ -73,7 +82,7 @@ bool try_get_hash_map_context_fixed(Variant& variant, const VExprContextSPtrs& e
key_byte_size += key_sizes.back();
}

size_t bitmap_size = has_null ? get_bitmap_size(expr_ctxs.size()) : 0;
size_t bitmap_size = has_null ? get_bitmap_size(data_types.size()) : 0;
if (bitmap_size + key_byte_size > sizeof(UInt256)) {
use_fixed_key = false;
}
Expand Down
12 changes: 11 additions & 1 deletion be/src/vec/exec/join/vhash_join_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,18 @@ void HashJoinNode::_hash_table_init(RuntimeState* state) {
return;
}

std::vector<DataTypePtr> data_types;
for (size_t i = 0; i != _build_expr_ctxs.size(); ++i) {
auto& ctx = _build_expr_ctxs[i];
auto data_type = ctx->root()->data_type();
if (_should_convert_build_side_to_nullable[i]) {
data_type = make_nullable(data_type);
}
data_types.emplace_back(std::move(data_type));
}

if (!try_get_hash_map_context_fixed<JoinHashMap, HashCRC32>(*_hash_table_variants,
_build_expr_ctxs)) {
data_types)) {
_hash_table_variants->emplace<SerializedHashTableContext>();
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,11 @@
2 111 111
3 1111 1111

-- !sql30 --
1 11 11 1 11 11
2 111 111 4 111 111
2 111 111 2 111 111
3 1111 1111 3 1111 1111
4 \N \N \N \N \N
5 1111 1111 3 1111 1111

Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,13 @@ suite("test_half_join_nullable_build_side", "query,p0") {
test_half_join_nullable_build_side_l2 l right semi join test_half_join_nullable_build_side_r2 r on l.v2 = r.v2
order by 1, 2, 3;
"""

qt_sql30 """
select
*
from
test_half_join_nullable_build_side_l2 l
left join test_half_join_nullable_build_side_l r on l.v2 <=> r.v2
order by 1, 2, 3;
"""
}