Fix ifnull/nvl expr result wrong precision

This commit is contained in:
hezuojiao
2023-04-27 02:14:22 +00:00
committed by ob-robot
parent f59bb29409
commit bc1c4b7599
6 changed files with 70 additions and 32 deletions

View File

@ -80,9 +80,15 @@ int ObExprIfNull::calc_result_type2(ObExprResType &type,
} else {
type.set_scale(-1);
}
if (lib::is_mysql_mode() && ob_is_real_type(type.get_type()) &&
SCALE_UNKNOWN_YET != type.get_scale()) {
type.set_precision(static_cast<ObPrecision>(ObMySQLUtil::float_length(type.get_scale())));
if (lib::is_mysql_mode() && SCALE_UNKNOWN_YET != type.get_scale()) {
if (ob_is_real_type(type.get_type())) {
type.set_precision(static_cast<ObPrecision>(ObMySQLUtil::float_length(type.get_scale())));
} else if (ob_is_number_tc(type.get_type())) { // TODO:@zuojiao.hzj add decimal_int here
const int16_t intd1 = type1.get_precision() - type1.get_scale();
const int16_t intd2 = type2.get_precision() - type2.get_scale();
const int16_t prec = MAX(type.get_precision(), MAX(intd1, intd2) + type.get_scale());
type.set_precision(static_cast<ObPrecision>(prec));
}
}
type.set_length(MAX(type1.get_length(), type2.get_length()));
type1.set_calc_meta(type.get_obj_meta());