fix generate slave mapping broadcast join plan bug

This commit is contained in:
chimyue
2023-11-16 07:44:53 +00:00
committed by ob-robot
parent 3c38e827e0
commit 902c912433

View File

@ -8912,8 +8912,8 @@ int ObJoinOrder::get_distributed_join_method(Path &left_path,
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
bool is_basic = false; bool is_basic = false;
bool is_remote = false; bool is_remote = false;
bool is_match_repart = false; bool is_left_match_repart = false;
bool is_match_single_side_hash = false; bool is_right_match_repart = false;
bool is_partition_wise = false; bool is_partition_wise = false;
bool is_ext_partition_wise = false; bool is_ext_partition_wise = false;
bool right_is_base_table = false; bool right_is_base_table = false;
@ -9149,150 +9149,125 @@ int ObJoinOrder::get_distributed_join_method(Path &left_path,
OPT_TRACE("plan will not use ext partition wise method"); OPT_TRACE("plan will not use ext partition wise method");
} }
} }
// check if match left re-partition
if (OB_SUCC(ret) && (distributed_methods & DIST_PARTITION_NONE)) { if (OB_SUCC(ret) &&
OPT_TRACE("check partition none method"); ((distributed_methods & DIST_PARTITION_NONE)
if (NULL == right_path.get_strong_sharding()) { || (distributed_methods & DIST_HASH_NONE)
is_match_repart = false; || ((distributed_methods & DIST_BROADCAST_NONE) && path_info.force_slave_mapping_))) {
OPT_TRACE("strong sharding of right path is null, not use partition none"); target_part_keys.reuse();
} else if (!right_path.get_sharding()->is_distributed_with_table_location_and_partitioning()) { if (OB_FAIL(right_sharding->get_all_partition_keys(target_part_keys, true))) {
is_match_repart = false;
OPT_TRACE("right path not meet repart");
} else if (OB_FAIL(right_sharding->get_all_partition_keys(target_part_keys, true))) {
LOG_WARN("failed to get partition keys", K(ret)); LOG_WARN("failed to get partition keys", K(ret));
} else if (OB_FAIL(ObShardingInfo::check_if_match_repart_or_rehash(equal_sets, } else if (OB_FAIL(ObShardingInfo::check_if_match_repart_or_rehash(equal_sets,
left_join_keys, left_join_keys,
right_join_keys, right_join_keys,
target_part_keys, target_part_keys,
is_match_repart))) { is_right_match_repart))) {
LOG_WARN("failed to check if match repartition", K(ret)); LOG_WARN("failed to check if match repartition", K(ret));
} else { /*do nothing*/ } }
}
if (OB_SUCC(ret)) { if (OB_SUCC(ret) &&
bool need_reduce_dop = right_path.parallel_more_than_part_cnt(); ((distributed_methods & DIST_NONE_PARTITION)
if (!is_match_repart) { || (distributed_methods & DIST_NONE_HASH)
OPT_TRACE("plan will not use partition none method"); || ((distributed_methods & DIST_NONE_BROADCAST) && path_info.force_slave_mapping_))) {
distributed_methods &= ~DIST_PARTITION_NONE; target_part_keys.reuse();
if (path_info.force_slave_mapping_) { if (OB_FAIL(left_sharding->get_all_partition_keys(target_part_keys, true))) {
OPT_TRACE("force slave mapping and prune broadcast/bc2host none method"); LOG_WARN("failed to get partition keys", K(ret));
distributed_methods &= ~DIST_BROADCAST_NONE; } else if (OB_FAIL(ObShardingInfo::check_if_match_repart_or_rehash(equal_sets,
if (use_shared_hash_join && HASH_JOIN == join_algo) { right_join_keys,
distributed_methods &= ~DIST_BC2HOST_NONE; left_join_keys,
} target_part_keys,
} is_left_match_repart))) {
} else if (need_reduce_dop) { LOG_WARN("failed to check if match repartition", K(ret));
OPT_TRACE("plan will use partition none method with parallel degree reduced"); }
} else { }
OPT_TRACE("plan will use partition none method and prune broadcast/bc2host/hash none method");
distributed_methods &= ~DIST_BROADCAST_NONE; // check if match left re-partition
distributed_methods &= ~DIST_HASH_NONE; if (OB_SUCC(ret) && (distributed_methods & DIST_PARTITION_NONE)) {
if (use_shared_hash_join && HASH_JOIN == join_algo) { OPT_TRACE("check partition none method");
distributed_methods &= ~DIST_BC2HOST_NONE; if (NULL == right_path.get_strong_sharding()) {
} OPT_TRACE("strong sharding of right path is null, not use partition none");
need_pull_to_local = right_path.exchange_allocated_; distributed_methods &= ~DIST_PARTITION_NONE;
} else if (!right_path.get_sharding()->is_distributed_with_table_location_and_partitioning()
|| !is_right_match_repart) {
OPT_TRACE("right path not meet repart, not use partition none");
distributed_methods &= ~DIST_PARTITION_NONE;
} else if (right_path.parallel_more_than_part_cnt()) {
OPT_TRACE("plan will use partition none method with parallel degree reduced");
} else {
OPT_TRACE("plan will use partition none method and prune broadcast/bc2host/hash none method");
distributed_methods &= ~DIST_BROADCAST_NONE;
distributed_methods &= ~DIST_HASH_NONE;
if (use_shared_hash_join && HASH_JOIN == join_algo) {
distributed_methods &= ~DIST_BC2HOST_NONE;
} }
need_pull_to_local = right_path.exchange_allocated_;
} }
} }
// check if match hash none // check if match hash none
if (OB_SUCC(ret) && (distributed_methods & DIST_HASH_NONE)) { if (OB_SUCC(ret) && (distributed_methods & DIST_HASH_NONE)) {
OPT_TRACE("check hash none method"); OPT_TRACE("check hash none method");
target_part_keys.reuse();
if (NULL == right_path.get_strong_sharding()) { if (NULL == right_path.get_strong_sharding()) {
is_match_single_side_hash = false;
OPT_TRACE("strong sharding of right path is null, not use hash none"); OPT_TRACE("strong sharding of right path is null, not use hash none");
distributed_methods &= ~DIST_HASH_NONE;
} else if (!right_sharding->is_distributed_without_table_location_with_partitioning() || } else if (!right_sharding->is_distributed_without_table_location_with_partitioning() ||
!ObShardingInfo::is_shuffled_server_list(right_path.get_server_list())) { !ObShardingInfo::is_shuffled_server_list(right_path.get_server_list()) ||
is_match_single_side_hash = false; !is_right_match_repart) {
} else if (OB_FAIL(right_sharding->get_all_partition_keys(target_part_keys, true))) { OPT_TRACE("plan will not use hash none method");
LOG_WARN("failed to get partition keys", K(ret)); distributed_methods &= ~DIST_HASH_NONE;
} else if (OB_FAIL(ObShardingInfo::check_if_match_repart_or_rehash(equal_sets, } else {
left_join_keys, OPT_TRACE("plan will use hash none method and prune broadcast none method");
right_join_keys, distributed_methods &= ~DIST_BROADCAST_NONE;
target_part_keys,
is_match_single_side_hash))) {
LOG_WARN("failed to check if match hash-none", K(ret));
} else { /*do nothing*/ }
if (OB_SUCC(ret)) {
if (!is_match_single_side_hash) {
OPT_TRACE("plan will not use hash none method");
distributed_methods &= ~DIST_HASH_NONE;
} else {
OPT_TRACE("plan will use hash none method and prune broadcast none method");
// not prune DIST_BC2HOST_NONE under shared hash join
distributed_methods &= ~DIST_BROADCAST_NONE;
}
} }
} }
// check if match right re-partition // check if match right re-partition
if (OB_SUCC(ret) && (distributed_methods & DIST_NONE_PARTITION)) { if (OB_SUCC(ret) && (distributed_methods & DIST_NONE_PARTITION)) {
OPT_TRACE("check none partition method"); OPT_TRACE("check none partition method");
target_part_keys.reuse();
if (NULL == left_path.get_strong_sharding()) { if (NULL == left_path.get_strong_sharding()) {
is_match_repart = false;
OPT_TRACE("strong sharding of left path is null, not use none partition"); OPT_TRACE("strong sharding of left path is null, not use none partition");
} else if (!left_path.get_sharding()->is_distributed_with_table_location_and_partitioning()) { distributed_methods &= ~DIST_NONE_PARTITION;
is_match_repart = false; } else if (!left_path.get_sharding()->is_distributed_with_table_location_and_partitioning()
OPT_TRACE("left path not meet repart"); || !is_left_match_repart) {
} else if (OB_FAIL(left_sharding->get_all_partition_keys(target_part_keys, true))) { OPT_TRACE("left path not meet repart, not use none partition");
LOG_WARN("failed to get all partition keys", K(ret)); distributed_methods &= ~DIST_NONE_PARTITION;
} else if (OB_FAIL(ObShardingInfo::check_if_match_repart_or_rehash(equal_sets, } else if (left_path.parallel_more_than_part_cnt()) {
right_join_keys, OPT_TRACE("plan will use none partition method with parallel degree reduced");
left_join_keys, } else {
target_part_keys, OPT_TRACE("plan will use none partition method and prune none broadcast/hash method");
is_match_repart))) { distributed_methods &= ~DIST_NONE_BROADCAST;
LOG_WARN("failed to check if match repartition", K(ret)); distributed_methods &= ~DIST_NONE_HASH;
} else { /*do nothing*/ } need_pull_to_local = false;
if (OB_SUCC(ret)) {
bool need_reduce_dop = left_path.parallel_more_than_part_cnt();
if (!is_match_repart) {
OPT_TRACE("plan will not use none partition method");
distributed_methods &= ~DIST_NONE_PARTITION;
if (path_info.force_slave_mapping_) {
OPT_TRACE("force slave mapping and prune none broadcast method");
distributed_methods &= ~DIST_NONE_BROADCAST;
}
} else if (need_reduce_dop) {
OPT_TRACE("plan will use none partition method with parallel degree reduced");
} else {
OPT_TRACE("plan will use none partition method and prune none broadcast/hash method");
distributed_methods &= ~DIST_NONE_BROADCAST;
distributed_methods &= ~DIST_NONE_HASH;
need_pull_to_local = false;
}
} }
} }
// check if match none-hash // check if match none-hash
if (OB_SUCC(ret) && (distributed_methods & DIST_NONE_HASH)) { if (OB_SUCC(ret) && (distributed_methods & DIST_NONE_HASH)) {
OPT_TRACE("check none hash method"); OPT_TRACE("check none hash method");
target_part_keys.reuse();
if (NULL == left_path.get_strong_sharding()) { if (NULL == left_path.get_strong_sharding()) {
is_match_single_side_hash = false;
OPT_TRACE("strong sharding of left path is null, not use none hash"); OPT_TRACE("strong sharding of left path is null, not use none hash");
distributed_methods &= ~DIST_NONE_HASH;
} else if (!left_sharding->is_distributed_without_table_location_with_partitioning() || } else if (!left_sharding->is_distributed_without_table_location_with_partitioning() ||
!ObShardingInfo::is_shuffled_server_list(left_path.get_server_list())) { !ObShardingInfo::is_shuffled_server_list(left_path.get_server_list()) ||
is_match_single_side_hash = false; !is_left_match_repart) {
} else if (OB_FAIL(left_sharding->get_all_partition_keys(target_part_keys, true))) { OPT_TRACE("plan will not use none hash method");
LOG_WARN("failed to get all partition keys", K(ret)); distributed_methods &= ~DIST_NONE_HASH;
} else if (OB_FAIL(ObShardingInfo::check_if_match_repart_or_rehash(equal_sets, } else {
right_join_keys, OPT_TRACE("plan will use none hash method and prune none broadcast method");
left_join_keys, distributed_methods &= ~DIST_NONE_BROADCAST;
target_part_keys,
is_match_single_side_hash))) {
LOG_WARN("failed to check if match none-hash", K(ret));
} else { /*do nothing*/ }
if (OB_SUCC(ret)) {
if (!is_match_single_side_hash) {
OPT_TRACE("plan will not use none hash method");
distributed_methods &= ~DIST_NONE_HASH;
} else {
OPT_TRACE("plan will use none hash method and prune none broadcast method");
distributed_methods &= ~DIST_NONE_BROADCAST;
}
} }
} }
if (OB_SUCC(ret) && (distributed_methods & DIST_BROADCAST_NONE)
&& path_info.force_slave_mapping_ && !is_right_match_repart) {
OPT_TRACE("force slave mapping and right path not meet repart, prune broadcast none method");
distributed_methods &= ~DIST_BROADCAST_NONE;
}
if (OB_SUCC(ret) && (distributed_methods & DIST_NONE_BROADCAST)
&& path_info.force_slave_mapping_ && !is_left_match_repart) {
OPT_TRACE("force slave mapping and left path not meet repart, prune none broadcast method");
distributed_methods &= ~DIST_NONE_BROADCAST;
}
/* /*
* if we have other parallel join methods, avoid pull to local execution, * if we have other parallel join methods, avoid pull to local execution,
* we may change this strategy in future * we may change this strategy in future