fix pdml error when target table is partitioned by functions, instead of ref columns

This commit is contained in:
raywill
2022-04-08 14:01:42 +08:00
committed by LINxiansheng
parent 76ae3d87cd
commit 5ac5277876
7 changed files with 130 additions and 14 deletions

View File

@ -3745,6 +3745,86 @@ int ObLogicalOperator::compute_repartition_func_info(const EqualSets& equal_sets
return ret;
}
int ObLogicalOperator::compute_repartition_func_info_for_insert(const ObIArray<ObRawExpr *> &src_keys,
const ObIArray<ObRawExpr *> &target_keys, const ObShardingInfo &target_sharding, ObRawExprFactory &expr_factory,
ObExchangeInfo &exch_info)
{
int ret = OB_SUCCESS;
ObSQLSessionInfo *session_info = NULL;
ObSEArray<ObRawExpr *, 4> repart_exprs;
ObSEArray<ObRawExpr *, 4> repart_sub_exprs;
ObSEArray<ObRawExpr *, 4> repart_func_exprs;
// get repart exprs
bool skip_part = target_sharding.is_partition_single();
bool skip_subpart = target_sharding.is_subpartition_single();
if (!skip_part && OB_SUCC(ret)) {
if (OB_FAIL(ObRawExprUtils::copy_exprs(
expr_factory, target_sharding.get_partition_keys(), repart_exprs, COPY_REF_DEFAULT))) {
LOG_WARN("fail copy expr", K(ret));
}
}
if (!skip_subpart && OB_SUCC(ret)) {
if (OB_FAIL(ObRawExprUtils::copy_exprs(
expr_factory, target_sharding.get_sub_partition_keys(), repart_sub_exprs, COPY_REF_DEFAULT))) {
LOG_WARN("fail copy expr", K(ret));
}
}
if (OB_FAIL(ret)) {
// pass
} else if (OB_ISNULL(get_plan()) ||
OB_ISNULL(session_info = get_plan()->get_optimizer_context().get_session_info())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(get_plan()), K(session_info), K(ret));
} else if (!skip_part && OB_FAIL(ObTransformUtils::replace_equal_expr(target_keys, src_keys, repart_exprs))) {
LOG_WARN("failed to get repartition keys", K(ret), K(target_keys), K(src_keys));
} else if (!skip_subpart && OB_FAIL(ObTransformUtils::replace_equal_expr(target_keys, src_keys, repart_sub_exprs))) {
LOG_WARN("failed to get repartition keys", K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < target_sharding.get_partition_func().count(); i++) {
ObRawExpr *repart_func_expr = NULL;
ObRawExpr *target_func_expr = target_sharding.get_partition_func().at(i);
if ((0 == i && skip_part) || (1 == i && skip_subpart)) {
ObConstRawExpr *const_expr = NULL;
ObRawExpr *dummy_expr = NULL;
int64_t const_value = 1;
if (OB_FAIL(ObRawExprUtils::build_const_int_expr(
get_plan()->get_optimizer_context().get_expr_factory(), ObIntType, const_value, const_expr))) {
LOG_WARN("Failed to build const expr", K(ret));
} else if (OB_ISNULL(dummy_expr = const_expr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else if (OB_FAIL(dummy_expr->formalize(session_info))) {
LOG_WARN("Failed to formalize a new expr", K(ret));
} else if (OB_FAIL(repart_func_exprs.push_back(dummy_expr))) {
LOG_WARN("failed to push back expr", K(ret));
}
} else if (OB_ISNULL(target_func_expr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else if (OB_FAIL(
ObRawExprUtils::copy_expr(expr_factory, target_func_expr, repart_func_expr, COPY_REF_DEFAULT))) {
LOG_WARN("failed to deep copy the partition fuc raw expr");
} else if (OB_ISNULL(repart_func_expr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else if (OB_FAIL(ObTransformUtils::replace_equal_expr(target_keys, src_keys, repart_func_expr))) {
LOG_WARN("failed to replace general expr", K(ret));
} else if (OB_FAIL(repart_func_exprs.push_back(repart_func_expr))) {
LOG_WARN("failed to push back expr", K(ret));
} else { /*do nothing*/
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(exch_info.set_repartition_info(repart_exprs, repart_sub_exprs, repart_func_exprs))) {
LOG_WARN("failed to set repartition keys", K(ret));
} else { /*do nothing*/
}
}
}
return ret;
}
int ObLogicalOperator::get_repartition_keys(const EqualSets& equal_sets, const ObIArray<ObRawExpr*>& src_keys,
const ObIArray<ObRawExpr*>& target_keys, const ObIArray<ObRawExpr*>& target_part_keys,
ObIArray<ObRawExpr*>& src_part_keys)
@ -3783,7 +3863,7 @@ int ObLogicalOperator::get_repartition_keys(const EqualSets& equal_sets, const O
}
if (OB_SUCC(ret) && !is_find) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("can not find part expr", K(target_part_keys.at(i)), K(src_keys), K(target_keys), K(ret));
LOG_WARN("can not find part expr", K(*target_part_keys.at(i)), K(src_keys), K(target_keys), K(ret));
}
}
}