Fix sum(bit_col) type dedction

This commit is contained in:
obdev
2024-02-07 17:34:44 +00:00
committed by ob-robot
parent 58c6dc8cd4
commit a73356831a

View File

@ -1659,12 +1659,7 @@ int ObRawExprDeduceType::visit(ObAggFunRawExpr &expr)
// But for expression like sum(sum()), the outer sum() is generated by // 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. // 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()) {
if (child_expr->get_expr_type() == T_FUN_SYS_CAST if (ob_is_integer_type(obj_type)) {
&& child_expr->has_flag(IS_OP_OPERAND_IMPLICIT_CAST)
&& ob_is_decimal_int(obj_type)) {
// child is implicit cast expr means precision already adjusted
// do nothing
} else if (ob_is_integer_type(obj_type)) {
const int16_t int_max_prec = ObAccuracy::MAX_ACCURACY2[0/*mysql mode*/][obj_type].get_precision(); 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; result_precision = MAX(result_precision, int_max_prec) + OB_DECIMAL_LONGLONG_DIGITS;
result_precision = MIN(OB_MAX_DECIMAL_PRECISION, result_precision); result_precision = MIN(OB_MAX_DECIMAL_PRECISION, result_precision);
@ -1930,9 +1925,10 @@ int ObRawExprDeduceType::visit(ObAggFunRawExpr &expr)
if (T_FUN_AVG == expr.get_expr_type() && -2 != scale_increment_recover) { if (T_FUN_AVG == expr.get_expr_type() && -2 != scale_increment_recover) {
result_type.set_calc_scale(scale_increment_recover); result_type.set_calc_scale(scale_increment_recover);
} }
if (T_FUN_SUM == expr.get_expr_type() && ObObjType child_type = expr.get_param_expr(0)->get_result_type().get_type();
ob_is_bit_tc(expr.get_param_expr(0)->get_result_type().get_type())) { if (T_FUN_SUM == expr.get_expr_type() && result_type.get_calc_meta().is_decimal_int()
// set calc precision as child precision for bit type. && (!ob_is_integer_type(child_type) && !ob_is_decimal_int(child_type))) {
// set calc precision as child precision for types other than integers
result_type.set_calc_precision(expr.get_param_expr(0)->get_result_type().get_precision()); result_type.set_calc_precision(expr.get_param_expr(0)->get_result_type().get_precision());
} }
expr.set_result_type(result_type); expr.set_result_type(result_type);