Fix decimal sum precision deduce not idempotent

This commit is contained in:
hezuojiao
2024-05-28 13:54:12 +00:00
committed by ob-robot
parent 47a371d554
commit db82be8c7e
4 changed files with 13 additions and 2 deletions

View File

@ -1701,7 +1701,8 @@ int ObRawExprDeduceType::visit(ObAggFunRawExpr &expr)
// In mysql mode, the precision of sum() will increase by OB_DECIMAL_LONGLONG_DIGITS.
// But for expression like sum(sum()), the outer sum() is generated by
// aggregation pushdown, so we don't need to accumulate precision for the outer expr.
if (T_FUN_SUM == expr.get_expr_type() && T_FUN_SUM != child_expr->get_expr_type()) {
if (T_FUN_SUM == expr.get_expr_type() && (T_FUN_SUM != child_expr->get_expr_type() ||
!expr.has_flag(IS_INNER_ADDED_EXPR))) {
if (ob_is_integer_type(obj_type)) {
const int16_t int_max_prec = ObAccuracy::MAX_ACCURACY2[0/*mysql mode*/][obj_type].get_precision();
result_precision = MAX(result_precision, int_max_prec) + OB_DECIMAL_LONGLONG_DIGITS;

View File

@ -441,12 +441,15 @@ int ObRawExprInfoExtractor::visit(ObCaseOpRawExpr &expr)
int ObRawExprInfoExtractor::visit(ObAggFunRawExpr &expr)
{
int ret = OB_SUCCESS;
const bool is_inner_added = expr.has_flag(IS_INNER_ADDED_EXPR);
if (OB_FAIL(clear_info(expr))) {
LOG_WARN("fail to clear info", K(ret));
} else if (OB_FAIL(pull_info(expr))) {
LOG_WARN("fail to add pull info", K(ret));
} else if (OB_FAIL(expr.add_flag(IS_AGG))) {
LOG_WARN("failed to add flag IS_AGG", K(ret));
LOG_WARN("failed to add flag IS_AGG", K(ret));
} else if (is_inner_added && OB_FAIL(expr.add_flag(IS_INNER_ADDED_EXPR))) {
LOG_WARN("failed to add inner added expr flag", K(ret));
} else { }
return ret;
}

View File

@ -8507,6 +8507,8 @@ int ObRawExprUtils::build_common_aggr_expr(ObRawExprFactory &expr_factory,
} else if (OB_ISNULL(aggr_expr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("agg_expr is null", K(ret), K(aggr_expr));
} else if (OB_FAIL(aggr_expr->add_flag(IS_INNER_ADDED_EXPR))) {
LOG_WARN("failed to add flag", K(ret));
} else if (OB_FAIL(aggr_expr->add_real_param_expr(param_expr))) {
LOG_WARN("failed to add param expr to agg expr", K(ret));
} else if (OB_FAIL(aggr_expr->formalize(session_info))) {