fix bug: the compare function for the runtime filter cannot be selected when the collation types of the join keys are different

This commit is contained in:
obdev 2023-07-03 07:12:54 +00:00 committed by ob-robot
parent 8dd2ef76dc
commit e32862ac75
3 changed files with 52 additions and 17 deletions

View File

@ -2550,6 +2550,11 @@ int ObStaticEngineCG::generate_spec(ObLogJoinFilter &op, ObJoinFilterSpec &spec,
// for use filter op, the compare funcs are used to compare left and right
// the compare funcs will be stored in ObExprJoinFilterContext finally
const common::ObIArray<common::ObDatumCmpFuncType> &join_filter_cmp_funcs = op.get_join_filter_cmp_funcs();
if (join_filter_cmp_funcs.count() != spec.join_keys_.count()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("compare func count not match with join_keys count",
K(join_filter_cmp_funcs.count()), K(spec.join_keys_.count()));
}
for (int64_t i = 0; i < spec.join_keys_.count() && OB_SUCC(ret); ++i) {
ObExpr *join_expr = spec.join_keys_.at(i);
ObHashFunc hash_func;
@ -2559,7 +2564,8 @@ int ObStaticEngineCG::generate_spec(ObLogJoinFilter &op, ObJoinFilterSpec &spec,
if (OB_ISNULL(hash_func.hash_func_) || OB_ISNULL(hash_func.batch_hash_func_) ||
OB_ISNULL(cmp_func.cmp_func_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("hash func or cmp func is null, check datatype is valid", K(ret));
LOG_WARN("hash func or cmp func is null, check datatype is valid",
K(hash_func.hash_func_), K(cmp_func.cmp_func_));
} else if (OB_FAIL(spec.hash_funcs_.push_back(hash_func))) {
LOG_WARN("failed to push back hash func", K(ret));
} else if (OB_FAIL(spec.cmp_funcs_.push_back(cmp_func))) {

View File

@ -4518,6 +4518,44 @@ int ObLogicalOperator::add_partition_join_filter_info(
return ret;
}
int ObLogicalOperator::cal_runtime_filter_compare_func(
ObLogJoinFilter *join_filter_use,
ObRawExpr *join_use_expr,
ObRawExpr *join_create_expr)
{
int ret = OB_SUCCESS;
if (ob_is_string_or_lob_type(join_use_expr->get_result_type().get_type())
|| ob_is_string_or_lob_type(join_create_expr->get_result_type().get_type())) {
if (OB_UNLIKELY(join_use_expr->get_collation_type() != join_create_expr->get_collation_type())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("collation type not match", K(join_use_expr->get_result_type()),
K(join_create_expr->get_result_type()));
}
}
if (OB_SUCC(ret)) {
ObCmpFunc cmp_func;
const ObScale scale = ObDatumFuncs::max_scale(join_use_expr->get_result_type().get_scale(),
join_create_expr->get_result_type().get_scale());
bool has_lob_header = is_lob_storage(join_use_expr->get_data_type())
|| is_lob_storage(join_create_expr->get_data_type());
cmp_func.cmp_func_ = ObDatumFuncs::get_nullsafe_cmp_func(
join_use_expr->get_data_type(),
join_create_expr->get_data_type(),
lib::is_oracle_mode()? NULL_LAST : NULL_FIRST,
join_use_expr->get_collation_type(),
scale,
lib::is_oracle_mode(),
has_lob_header);
if (OB_ISNULL(cmp_func.cmp_func_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("cmp_func_ is null", K(join_use_expr->get_result_type()), K(join_create_expr->get_result_type()));
} else {
join_filter_use->add_join_filter_cmp_funcs(cmp_func.cmp_func_);
}
}
return ret;
}
int ObLogicalOperator::generate_runtime_filter_expr(
ObLogicalOperator *op,
ObLogicalOperator *join_filter_create_op,
@ -4550,22 +4588,9 @@ int ObLogicalOperator::generate_runtime_filter_expr(
LOG_WARN("join_use_expr or join_create_expr is NULL!", K(join_use_expr), K(join_create_expr));
} else if (OB_FAIL(join_filter_expr->add_param_expr(join_use_exprs.at(i)))) {
LOG_WARN("fail to add param expr", K(ret));
} else {
CK(join_use_expr->get_collation_type() == join_create_expr->get_collation_type());
ObCmpFunc cmp_func;
const ObScale scale = ObDatumFuncs::max_scale(join_use_expr->get_result_type().get_scale(),
join_create_expr->get_result_type().get_scale());
bool has_lob_header = is_lob_storage(join_use_expr->get_data_type())
|| is_lob_storage(join_create_expr->get_data_type());
cmp_func.cmp_func_ = ObDatumFuncs::get_nullsafe_cmp_func(
join_use_expr->get_data_type(),
join_create_expr->get_data_type(),
lib::is_oracle_mode()? NULL_LAST : NULL_FIRST,
join_use_expr->get_collation_type(),
scale,
lib::is_oracle_mode(),
has_lob_header);
join_filter_use->add_join_filter_cmp_funcs(cmp_func.cmp_func_);
} else if (join_filter_use->get_join_filter_cmp_funcs().count() < join_use_exprs.count()
&& OB_FAIL(cal_runtime_filter_compare_func(join_filter_use, join_use_expr, join_create_expr))) {
LOG_WARN("fail to cal compare function", K(ret));
}
}
if (OB_SUCC(ret)) {

View File

@ -1798,6 +1798,10 @@ private:
ObLogicalOperator *join_filter_use_op,
double join_filter_rate,
RuntimeFilterType type);
int cal_runtime_filter_compare_func(
ObLogJoinFilter *join_filter_use,
ObRawExpr *join_use_expr,
ObRawExpr *join_create_expr);
/* manual set dop for each dfo */